[{"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"}]}]
Excel文件的导入导出是一种常见且便捷的数据处理方式。通过使用Excel,用户可以将数据从在线的SpreadJS导出为Excel文件,或者将Excel文件导入到SpreadJS中进行在线预览。
那些经常使用SpreadJS进行Excel文件导入导出操作的用户对于gc.spread.Excelio这个包并不陌生,它是我们导出Excel文件的核心依赖。如果没有它,就无法实现对Excel文件的导入导出。
这个依赖的上架可以追溯到SpreadJS V9.0版本。在此之前,SpreadJS的Excel导入/导出功能要求将其安装在网络服务器上。用户想要导出Excel文件就必须依赖后端,这对于网络延迟和开发成本都有一定的负担。因此,在V9.0版本中,我们将导入导出Excel文件的功能作为一个组件,并提供公共接口以方便用户调用。
使用ExcelIO的用户都知道,要将在线文件导出为Excel文件,首先需要创建ExcelIO的实例,然后使用ExcelIO的save方法将在线文件导出为SSJSON格式,最后使用FileSaver库的saveAs方法将SSJSON数据保存为Excel文件。代码如下:
var ExcelIO = new GC.Spread.Excel.IO();
ExcelIO.save(SSJSON, function (b) {
window.saveAs(b, "导出.XLSX");
}, function (e) {
console.log("导出失败");
});
随着越来越多的用户使用SpreadJS,我们收到了越来越多的使用大数据量和复杂格式文件的案例。这些大数据量的文件给产品的性能带来了新的挑战。如何提升性能成为决定用户在处理大数据量文件导入导出时体验的关键。因此,在SpreadJS V16.0正式发布后,我们推出了全新的文件结构——SJS。**这种新的结构不仅大幅减少了文档的体积,而且平均提升了导入导出性能高达50%。**这为未来涉及金融行业和协同编辑等大数据量场景下对低延迟性能的要求提供了架构级的基础支持。而对于之前为了解决前端导入导出需求而推出的ExcelIO,则到了告别的时候了。
为了应对未来ExcelIO在导入导出性能方面所面临的挑战,我们在SpreadJS v16.0版本中正式采用了一种新的文件格式来解决这个问题。这种新的.SJS格式是一个压缩文件,它包含了多个较小的JSON文件,类似于Excel的XML结构。
这种新的文件结构能够支持大型Excel文件,并将它们导出为体积更小的文件。此外,如果一个Excel文件中有许多工作表,您可以通过按需加载工作表的方式实现快速加载。为了使用这种新的文件格式,您无需再导入ExcelIO模块,而是只需导入IO插件即可:
"@grapecity-software/spread-sheets-io": "^16.2.4",
此时,可能会有一些用户会有疑问,即我们推出了SJS文件格式后是否不再支持之前的Excel的XLSX文件格式。答案是否定的。需要注意的是,新的SJS文件格式是可选的,您仍然可以选择使用.SSJSON格式或XLSX格式的文件。但是,如果您希望获得更小的文件体积和更快的性能,我们建议您使用.SJS文件格式。SJS格式和非SJS格式文件的导入导出方法也有所不同,前者使用open和save方法,后者使用import和export方法。代码如下:
export default {
name: "App",
data: function () {
return {
spread: null,
selectedFile: null
};
},
methods: {
spreadInitHandle(value) {
this.spread = value;
},
handleFileUpload(e) {
this.selectedFile = e.target.files[0];
},
uploadFile() {
let spread = this.spread
// 使用FormData对象来构建文件上传请求
let formData = new FormData();
formData.append('file', this.selectedFile);
// 解析文件名和文件类型
const fileName = this.selectedFile.name;
const fileExtension = fileName.split('.').pop();
if (fileExtension == "sjs") {
spread.open(this.selectedFile, function () { }, function () { });
} else {
spread.import(this.selectedFile, function () { }, function () { });
}
},
saveExcel() {
let spread = this.spread
console.log(spread);
spread.export(function (blob) { saveAs(blob, "test.xlsx"); }, function () { });
},
saveSJS() {
let spread = this.spread
spread.save(function (blob) { saveAs(blob, "test.sjs"); }, function () { });
},
saveSSJSON() {
let spread = this.spread
console.log(spread.toJSON());
}
},
};
相关文档参考:
新的文件格式的引入让SpreadJS在导入和导出方面具备了更高的性能和更小的文件体积。之前的导出方式是先将数据导出为SSJSON,然后再转换为Excel模型,而现在借助新的文件格式,数据直接被添加到一个压缩的.SJS文件中,这个文件包含了一些较小的SSJSON文件,类似于Excel XML结构。
在过去,ExcelIO Import和Export的实质是通过特殊的JSON和Excel模型转换为Excel XML。通过采用这种新的格式,SpreadJS将被转换为.SJS,这是一种类似于Excel XML的特殊JSON模式,因此可以直接进行转换操作。
以下是比较 .SSJSON 和 .SJS 示例文件的一些性能数据:
除了时间改进外,新文件格式还包括文件大小改进:
在保存或打开新的 SJS 文件时,这种新文件类型有几个不同的选项可供选择。这些包括:
导出选项
- includeBindingSource 是否包含绑定源
- includeStyles 是否包含样式
- includeFormulas 是否包含公式
- saveAsView 是否忽略格式字符串
- includeAutoMergedCells 是否包括自动合并的单元格
- includeCalcModelCache 是否包括计算引擎缓存
- includeUnusedNames 是否包括未被使用的命名信息
- includeEmptyRegionCells 是否包括空白区域
导入选项
- includeStyles 转换时是否包含样式
- includeFormulas 转换时是否包含公式
- fullRecalc 转换后是否执行计算引擎重算
- dynamicReferences 转换时是否以动态引用模式执行计算
- calcOnDemand 转换后是否按需计算公式
- includeUnusedStyles 转换时是否包括未被使用的命名信息
- openMode 导入模式
- Normal - 打开文件时,可以刷新UI和UI事件,会在特定时间点响应.
- Lazy - 打开文件时,只直接加载活动的工作表,其他工作表只有在使用时才加载.
- Incremental - 打开文件时,可以刷新UI和UI事件,并会立即响应.
还有用于导入和导出不同文件类型选项的特定选项:
- ImportXlsxOptions 导入XLSX文件选项
- ImportSSJsonOptions 导入SSJSON文件选项
- ImportCsvOptions 导入Csv文件选项
- ExportXlsxOptions 导出XLSX文件选项
- ExportSSJsonOptions 导出SSJSON文件选项
- ExportCsvOptions 导出Csv文件选项
作者: Richard.Huang | 审核:Clark.Pan | 更新时间:2023.11.06