Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - get superscript and subscript in excel

I am parsing an excel which has superscripts and subscripts and want to enclose them like this :

 <sup>superscripted value</sup> 
 <sub>subscripted value</sub>

tried using xlsx, excel parser and SheetJS to try and identify if the value has been superscripted/subscripted.

Is there any other way I can identify if the value has been subscripted/superscripted?

like image 717
master_gogo Avatar asked Mar 29 '26 02:03

master_gogo


1 Answers

try using xlsx-populate

let sup_sub_map = {
    "superscript": "<sup>",
    "superscriptEnd": "</sup>",
    "subscript": "<sub>",
    "subscriptEnd": "</sub>",
};

//assuming you have parsed till cell value:
cellValue.foreach(sub_value => {
    if (sub_value['children'].length > 1) {
       let type = sup_sub_map[sub_value['children'][0]["children"][0]["attributes"]["val"]];
       let endType = sup_sub_map[sub_value['children'][0]["children"][0]["attributes"]["val"] + "End"];
       newVal = newVal + type + sub_value['children'][1]["children"][0] + endType
    } else {
        newVal = newVal + sub_value["children"][0]["children"][0];
    }
});

Its not the cleanest or the best way to do this but certainly gets the job done. Havent come across any other library which gives a subscript/superscript identifier.

like image 186
Aniruddha Gohad Avatar answered Mar 31 '26 04:03

Aniruddha Gohad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!