1金币
本帖最后由 Clark.Pan 于 2023-12-19 10:16 编辑
导出页面内容+样式到excel,打开文件后出现文件格式已损坏 另外如何去除打开文件时的密码
var sheet = NB.getSheet;
var tables = sheet.tables;
// 获取表格的范围
var tableRange = sheet.tables.all()[0].range();
// 获取表格范围内的数据和样式
var tableData = sheet.getArray(tableRange.row, tableRange.col, tableRange.rowCount, tableRange.colCount);
var tableStyles = sheet.getActualStyle(tableRange.row, tableRange.col, GC.Spread.Sheets.SheetArea.viewport);
// 将数据和样式保存为 Excel 文件
var excelJson = {
sheets: [
{
name: "Sheet1",
data: tableData,
styles: tableStyles
}
]
};
var excelIO = new GC.Spread.Excel.IO();
excelIO.save(excelJson, function (blob) {
//saveAs(blob, fileName); //saveAs is from FileSaver.
funDownload(blob,"test.xlsx")
}, function (e) {
console.log(e);
}, {
password: "password",
xlsxStrictMode: false
});
var funDownload = function (content, filename) {
var eleLink = document.createElement('a');
eleLink.download = filename;
eleLink.style.display = 'none';
// 字符内容转变成blob地址
var blob = new Blob([content]);
eleLink.href = URL.createObjectURL(blob);
// 触发点击
document.body.appendChild(eleLink);
eleLink.click();
// 然后移除
document.body.removeChild(eleLink);
};
打不开文件 另外需要去掉密码
|
|