本帖最后由 Matthew.Xue 于 2025-3-11 14:13 编辑
您好,SpreadJS有toJSON和export方法,前者可以输出json字符串,后者可以将workbook实例转换为ssjson的blob流。
toJSON
export
import
您说的批量转换,其实就是创建多个workbook实例,依次导入excel文件,并循环使用toJSON或者export方法,这块的代码需要您自己实现,伪代码如下,您可以参考:
- let spreadList = []
- let fileList = [] // 文件列表需要从后端拿到,或者由用户自己上传
- // 批量导入excel文件
- fileList.forEach(xlsx => {
- let _spread = new GC.Spread.Sheets.Workbook()
- _spread.import(xlsx, function() {
- spreadList.push(_spread)
- })
- })
- // 批量导出为ssjson
- spreadList.forEach((_spread, idx) => {
- _spread.export(function (blob) {
- saveAs(blob, idx + ".ssjson") // saveAs方法为三方包file-saver所提供
- }, function() {}, {
- fileType: GC.Spread.Sheets.FileType.ssjson
- })
- })
复制代码
|