以下是我的代码
for (var i = 1; i <= viewModel.FileList.length; i++) {
var spread = new GC.Spread.Sheets.Workbook(document.getElementById(printAreaId));
var filePath = viewModel.OutputFileName[i - 1];
var excelIo = new GC.Spread.Excel.IO();
var excelFilePath = filePath;
var xhr = new XMLHttpRequest();
xhr.open('GET', excelFilePath, true);
xhr.responseType = 'blob';
xhr.onload = function (e) {
if (this.status == 200) {
// get binary data as a response
var blob = this.response;
// convert Excel to JSON
excelIo.open(blob, function (json) {
var workbookObj = json;
spread.fromJSON(workbookObj);
var sheets = spread.sheets;
sheets.forEach(function (sheet) {
setPrintInfo(filePath, sheet);
})
}, function (e) {
// process error
alert(e.errorMessage);
}, {});
}
};
xhr.send();
}
这样显示F12会报错
我只有将所有的变量都不重复才能显示
1:
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("printArea1"));
var filePath = viewModel.OutputFileName[0];
var excelIo = new GC.Spread.Excel.IO();
var excelFilePath = filePath
var xhr = new XMLHttpRequest();
xhr.open('GET', excelFilePath, true);
xhr.responseType = 'blob';
xhr.onload = function (e) {
if (this.status == 200) {
// get binary data as a response
var blob = this.response;
// convert Excel to JSON
excelIo.open(blob, function (json) {
var workbookObj = json;
spread.fromJSON(workbookObj);
var sheets = spread.sheets;
sheets.forEach(function (sheet) {
setPrintInfo(viewModel.OutputFileName[0], sheet);
})
}, function (e) {
// process error
alert(e.errorMessage);
}, {});
}
};
xhr.send();
2:
var spread2 = new GC.Spread.Sheets.Workbook(document.getElementById("printArea2"));
$("#print2").css("display", "");
$("#printArea2").css("display", "");
if (excelCheck) {
$("#save2").css("display", "");
}
var filePath2 = viewModel.OutputFileName[1];
var excelIo2 = new GC.Spread.Excel.IO();
var excelFilePath2 = filePath2;
var xhr2 = new XMLHttpRequest();
xhr2.open('GET', excelFilePath2, true);
xhr2.responseType = 'blob';
xhr2.onload = function (e) {
if (this.status == 200) {
// get binary data as a response
var blob2 = this.response;
// convert Excel to JSON
excelIo2.open(blob2, function (json) {
var workbookObj = json;
spread2.fromJSON(workbookObj);
var sheets = spread2.sheets;
sheets.forEach(function (sheet) {
setPrintInfo(viewModel.OutputFileName[1], sheet);
})
}, function (e) {
// process error
alert(e.errorMessage);
}, {});
}
};