找到了解决方法
$("#saveExcel").click(function () {
var fileName = $("#exportFileName").val();
var password = $("#password").val();
if (fileName.substr(-5, 5) !== '.xlsx') {
fileName += '.xlsx';
}
var json = JSON.stringify(spread.toJSON());
var tempSpread = new GC.Spread.Sheets.Workbook();
tempSpread.fromJSON(JSON.parse(json));
for (var pro in tempSpread.sheets) {
var sheet = tempSpread.sheets[pro];
var rowCount = sheet.getRowCount(), colCount = sheet.getColumnCount();
// 清除公式
for(var i = 0; i < rowCount; i++){
for(var j = 0; j < colCount; j++){
sheet.setFormula(i, j, undefined);
}
}
//复制列头
sheet.addRows(0,1)
for(var j = 0; j < colCount; j++){
sheet.setValue(0, j, sheet.getValue(0, j, GC.Spread.Sheets.SheetArea.colHeader))
}
}
//获取处理后的json
json = tempSpread.toJSON();
// here is excel IO API
excelIo.save(json, function (blob) {
saveAs(blob, fileName);
}, function (e) {
// process error
console.log(e);
}, {password: password});
}); |