表格开发控件Spread.Sheets前端打开服务器Excel
对于.Net用户可以使用服务端的ExcelIO组件将Excel文件解析成JSON后再在前端展示。但是对于其他平台用户就需要将Excel下载到前端后直接打开。具体实现方式请参考下面代码示例,首先下载Excel文件为Blob对象,然后用excelio 打开即可。
var spread = new GC.Spread.Sheets.Workbook(document.getElementB yId("ss"));
var excelIo = new GC.Spread.Excel.IO();
// Download Excel file
var excelFilePath = 'template.xlsx';
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);
}, function (e) {
// process error
alert(e.errorMessage);
}, {});
}
};
xhr.send();