Last active
September 19, 2024 12:26
-
-
Save lubobill1990/665ba76be8732514ab73cc3261c1f2f9 to your computer and use it in GitHub Desktop.
腾讯文档 Excel 获取只读 Excel 的文本内容
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 打开要导出的腾讯文档 Excel 页面 | |
// Control+Shift+I,打开 Chrome/Edge 网页调试工具 | |
// Control+Shift+F,源代码搜索 this.app.workbook.worksheetManager.activeSheet | |
// 双击搜索结果,在定位到的行的左侧加上断点(加完断点后,显示一个红色的点或者蓝色的标签) | |
// 刷新页面,等断点停止后,在控制台运行:window.workbook = this.app.workbook; | |
// 按下 F8 继续代码运行。等页面中表格全部显示后,控制台运行: | |
let lines = []; | |
window.workbook.worksheetManager.sheetList.forEach((sheet) => { | |
sheet.cellDataGrid.blockMatrix.forEach((row) => { | |
row[0].data.forEach((part) => { | |
let line = ""; | |
part.forEach(p => { | |
if (p.value !== undefined) { | |
const seperator = line === "" ? "": ", "; | |
let value = p.value; | |
if (typeof value === 'string') { | |
value = value.replace("\n", " "); | |
} else if (typeof value === 'object') { | |
value = value.r.map(t => t.t).join(" ").replace("\n", " "); | |
} | |
line += seperator + value; | |
} | |
}) | |
if (line !== "") { | |
lines.push(line); | |
} | |
}); | |
}); | |
}); | |
__console.log(lines.join("\n")); | |
// 将输出保存到文本文件,命名为 .csv 后缀,使用 Excel 打开 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can't search this.app.workbook.worksheetManager.activeSheet