[{"id":"b66f8b1e-cc14-4e89-9679-abd5687d283d","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"569bb90a-ea68-46c6-96f1-ab151c120714","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5eb52f08-2d1a-4362-9ffc-4871bdc10f3f","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"341dd607-b97d-4d70-bde2-53acda6b6c95","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"05349273-414f-4208-9ea2-c4fc8f4ea2cb","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"86089f76-b778-4d52-821e-6f27de3df613","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b81e4fd6-1fc5-43a0-a258-b6e16a5cbec6","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8aa8ce31-43e4-438e-951f-241608435260","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"37343f41-6ec2-4c7e-b21d-2cc18d5ce1e0","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5915e52f-64f8-4146-b8bd-81bead6324a3","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"836ba889-af9e-460d-a4cc-c24d922795f2","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4ae14b06-bb68-4394-a210-a46b8f028346","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d8f42066-e9dc-4411-bdcf-43b1a203370c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"7ef86f16-b1a0-49f7-9592-612b9be02b25","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b29c7775-a9a4-451e-a1b5-01d19ed5ca5e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"e56f3989-8f81-46af-90fa-a4813eeb976f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"2526c963-f170-45a8-923e-91b0712a9810","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"24575cf0-501a-44f9-8426-c40f8f4b5552","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1a6f8d7f-acd6-42be-8c4f-f464c6218381","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"82b176fd-5cab-498c-909e-8fa7d29c38d8","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1708b3a9-4f37-44a8-8f0e-f9a2d2e5d940","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"c9ac246e-29fb-4bc4-8231-8439795bb590","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"94f2a5c3-2539-436a-af75-23fbbd1a3957","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d99594f4-2d40-4df4-9419-ba2ca6aa3f7f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"fd66e72d-0f10-4f57-9807-6db26290ab2e","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8f344863-503d-4bc3-a594-3815e7d55f5c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"9be82601-de9d-4c18-948a-23ab6f4dd431","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"6495f3c0-b463-47e0-b08a-ca949672211e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b4bede08-3f08-4839-ba4a-abc7ac195bde","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4afcdfc0-3ff5-4f2b-a223-f8fc042a5bbe","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"422062c4-fa40-4771-a86f-008efe6d86e5","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d87e8013-86a7-4840-8d25-6f62e14eb4ac","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a6acedfd-4043-4c64-a5d1-aec3326df9e7","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"dbdc0b24-06c4-48b9-8d6c-7455119dc773","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a3856849-954a-4cfc-96a6-382e530d3638","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4a39306b-ffa5-433d-80a3-28e41f929b72","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]}]
SpreadJS允许用户在最短的时间内打开和保存大文件,并以不同的文件格式(如Excel、CSV、SSJSON(旧版SpreadJS格式)和SJS(新版更快的SpreadJS格式))导出或导入。
新的 SJS 格式在处理非常大的 Excel 文件时显著提高了加载时间和内存使用情况,并且与以前的 SpreadJS 版本相比,重新保存时大大减小了文件大小。
为了执行打开、保存、导入和导出等不同格式的文件操作,SpreadJS提供了 gc.spread.sheets.io.xxx.js
插件。
GC.Spread.Sheets.Workbook
类提供了以下方法来进行不同的文件操作。
方法 | 描述 |
---|---|
加载 SpreadJS 文件格式 | |
保存为 SpreadJS 文件格式 | |
导出文件为 Excel,、SSJSON 或 CSV 格式 | |
导入格式为 Excel,、SSJSON、CSV 或 JavaScript |
在以下部分中,我们将详细了解不同的文件操作。
您可以使用 open 方法在 SpreadJS 中加载 SpreadJS 文件。 此方法提供以下参数:
file blob:它代表压缩的电子表格数据文件流。
successCallBack:此函数在加载文件完成并接受 JSON 作为参数时提供成功回调。
errorCallBack:该函数在文件加载返回错误时给出错误回调。
openOptions:该参数继承自 GC.Spread.Sheets.OpenOptions
类型。
不同的打开选项如下:
选项 | 描述 |
---|---|
includeStyles | 表示是否在导入时包含样式,默认是包含(true) |
includeFormulas | 表示是否在导入时包含公式,默认是包含(true) |
fullRecalc | 表示是否在导入后进行全量计算,默认是计算(true) |
dynamicReferences | 表示是否进行动态引用计算,默认是计算(true) |
calcOnDemand | 表示是否开启按需计算模式,默认开启(true) |
includeUnusedStyles | 表示是否导入未使用的命名样式,默认为导入(true) |
openMode | 代表 标准( |
progress | 导入进度的回调函数,继承自 |
以下代码实现显示了如何执行打开文件操作:
//This example uses the open method.
//Get file blob.
var file = document.getElementById("fileInput").files[0];
// import
spread.open(file, function () {
// success callback to do something
}, function (e) {
console.log(e); // error callback
}, {
openMode: GC.Spread.Sheets.OpenMode.lazy,
includeFormulas: false,
includeStyles: false
});
您可以使用 save 方法保存 SpreadJS 文件,该方法提供以下参数:
successCallBack:当 SpreadJS 文件完全保存并接受 Blob 作为参数时,此函数会提供成功回调。
errorCallBack:该函数在保存 SpreadJS 文件返回错误时给出错误回调。
saveOptions:继承自 GC.Spread.Sheets.SaveOptions
类型定义,提供保存选项。
保存选项 | 描述 |
---|---|
includeBindingSource | 是否包含数据源,默认不包含(false) |
includeStyles | 是否包含样式,默认包含(true) |
includeFormulas | 是否包含公式,默认包含(true) |
saveAsView | 是否忽略格式,默认不忽略(false) |
includeAutoMergedCells | 是否包含自动合并的单元格,默认不包含(false) |
includeCalcModelCache | 保存文件时是否可以包含计算的额外数据。 默认情况下,值为 true。 |
includeUnusedNames | 保存文件时是否可以包含未使用的自定义名称。 默认情况下,值为 true。 |
includeEmptyRegionCells | 是否可以在使用的数据范围之外包含任何空单元格。 默认情况下,值为 true。 |
saveR1C1Formula | 指示是否将r1c1公式保存在文件中。默认情况下,该值为 false。 |
以下代码实现显示了如何执行保存文件操作:
var fileName = "fileNamehere.sjs";
spread.save(function (blob) {
// save blob to a file
saveAs(blob, fileName);
}, function (e) {
console.log(e);
}, {
includeUnusedNames: false,
includeEmptyRegionCells: false
});
您可以在 SpreadJS 中将文件导出为 Excel、SSJSON 或 CSV 格式。
导出方法提供以下参数:
successCallBack:此函数在文件导出完成并接受 Blob 作为参数时提供成功回调。
errorCallBack:该函数在导出文件返回错误时给出错误回调。
saveOptions:继承自 GC.Spread.Sheets.ExportOptions
类型定义,提供导出选项。
导出选项 | 描述 |
---|---|
FileOptions | 继承自 |
ExportCsvOptions | 继承自 |
ExportSSJsonOptions | 继承自 |
ExportXlsxOptions | 继承自 |
代码实现显示了如何执行导出文件操作:
var fileName = "fileNamehere.ssjson";
spread.export(function (blob) {
// save blob to a file
saveAs(blob, fileName);
}, function (e) {
console.log(e);
}, {
fileType: GC.Spread.Sheets.FileType.ssjson,
includeBindingSource: true
});
您还可以在 SpreadJS 中导入 Excel、SSJSON 或 CSV 格式的文件。
导入方法提供以下参数:
file:要导入的 SSJSON 或 CSV 或 Excel 文件。
successCallBack:此函数在文件导入完成时提供成功回调。
errorCallBack:此函数在导入文件返回错误时给出错误回调。
importOptions:继承自 GC.Spread.Sheets.ImportOptions
类型定义,提供导入选项。
选项 | 描述 |
---|---|
FileOptions | 继承自 |
ImportCsvOptions | 继承自 |
ImportSSJsonOptions | 继承自 |
ImportXlsxOptions | 继承自 |
代码实现显示了如何执行导入文件操作:
//Get file blob.
var file = document.getElementById("fileInput").files[0];
// import
spread.import(file, function () {
// success callback to do something
}, function (e) {
console.log(e); // error callback
}, {
fileType: GC.Spread.Sheets.FileType.excel
});