我正在解析一个具有上标和下标的 excel,并希望像这样将它们括起来:
<sup>superscripted value</sup>
<sub>subscripted value</sub>
尝试使用 xlsx、excel 解析器和 SheetJS 来尝试识别该值是否已被上标/下标。
有没有其他方法可以识别该值是否已下标/上标?
尝试使用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];
}
});
它不是最干净或最好的方法,但肯定可以完成工作。没有遇到任何其他提供下标/上标标识符的库。