本帖最后由 htkjtv 于 2024-9-20 16:16 编辑
workBookArray为工作表集合
var workBookArray = new Array();
for(var i=0;i<idArr.length;i++){var workbook = new GC.Spread.Sheets.Workbook(document.getElementById("wb"+i));
workbook.fromJSON(res);
workBookArray.push(workbook);
}
问题:
循环workBookArray集合批量导出excel
var excelIo = new GC.Spread.Excel.IO();
var serializationOption = {
includeBindingSource: true, // include binding source when converting the workbook to json, default value is false
//ignoreStyle: true, // ignore styles when converting workbook to json, default value is false
//ignoreFormula: true, // ignore formulas when converting workbook to json, default value is false
saveAsView: true, //include the format string formatting result when converting workbook to json, default value is false
//rowHeadersAsFrozenColumns: true, // treat row headers as frozen columns when converting workbook to json, default value is false
//columnHeadersAsFrozenRows: true, // treat column headers as frozen rows when converting workbook to json, default value is false
includeAutoMergedCells: true // include the automatically merged cells to the real merged cells when converting the workbook to json.
}
for(var i=0; i<workBookArray.length; i++) {
var spread = workBookArray[i];
var json = JSON.stringify(spread.toJSON(serializationOption));var sheet = spread.getSheet(0);
var fileName =sheet.getValue(1,1);
console.log(fileName); // 此处打印为每个表不同的内容
excelIo.save(json, function (blob) {
saveAs(blob, fileName + '.xlsx'); //但此处导出的都是最后一个
}, function (e) {
console.log(e);
});}
结果导出的这些表都是集合中的最后一个表,导出一堆一样的表,如何解决?
|
|