gpt4 book ai didi

Node.js - 在 excel 中获取上标和下标

转载 作者:搜寻专家 更新时间:2023-10-31 23:44:50 28 4
gpt4 key购买 nike

我正在解析一个具有上标和下标的 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];
}
});

这不是最干净或最好的方法,但肯定能完成工作。还没有遇到任何其他提供下标/上标标识符的库。

关于Node.js - 在 excel 中获取上标和下标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50485747/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com