[]
        
(Showing Draft Content)

Excel.IO-1

类: IO

Excel.IO

Table of contents

构造方法

方法

构造方法

constructor

new IO()

Excel 导入导出类

方法

open

open(file, successCallBack, errorCallBack?, options?): void

导入 Excel 文件(xlsx)

代码示例

var workbook = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
var excelIO = new GC.Spread.Excel.IO();
var excelFile = document.getElementById("fileDemo").files[0];
excelIO.open(excelFile, function (json) {
   workbook.fromJSON(json);
}, function (e) {
   console.log(e);
}, {
   password: "password",
   importPictureAsFloatingObject: false
});

参数

属性名 类型 说明
file Blob Excel 文件(xlsx)
successCallBack Function 成功后的回调函数
errorCallBack? Function 失败时的回调函数,错误参考: { errorCode: GC.Spread.Excel.IO.ErrorCode, errorMessage: string}.
options? OpenOptions 导入 Excel 的参数

返回值

void


registerMaxDigitWidth

registerMaxDigitWidth(fontFamily, fontSize, maxDigitWidth): void

向 Excel.IO 注册缺失字体宽度

参数

属性名 类型 说明
fontFamily string 默认样式字体的字体系列
fontSize number 默认样式字体的字体大小(以 point 为单位)
maxDigitWidth number 默认样式字体的最大宽度

返回值

void


save

save(json, successCallBack, errorCallBack?, options?): void

使用 SpreadJS JSON 创建并保存 Excel(xlsx) 文件

代码示例

var workbook = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
var excelIO = new GC.Spread.Excel.IO();
var json = JSON.stringify(workbook.toJSON());
excelIO.save(json, function (blob) {
   saveAs(blob, fileName); //saveAs is from FileSaver.
}, function (e) {
   console.log(e);
}, {
   password: "password",
   xlsxStrictMode: false
});

参数

属性名 类型 说明
json string | object SpreadJS JSON 对象(或字符串)
successCallBack Function 成功后的回调函数
errorCallBack? Function -
options? SaveOptions 导出 Excel 的参数

返回值

void