如果在spreadjs里面是表格区域内的合并单元格,导出Excel后,合并属性就会丢失,处理办法之一是:导出Excel前,将表格的属性去掉,仅保留原表格的样式和数据,这样导出合并属性可以保留
仅仅是导出Excel时获取JSON前这样处理,这个JSON处理后,不要去保存JSON,否则spreadjs里面表格属性就真丢失了
- function removeTableProperties() {
- var spread = designer.wrapper.spread;
- var sheetCount = spread.getSheetCount();
- for (var i = 0; i < sheetCount; i++) {
- var sheet = spread.getSheet(i);
- sheet.suspendCalcService(false);
- sheet.suspendDirty(false);
-
- var tables = sheet.tables.all();
- if (tables) {
- for (var j = 0; j < tables.length; j++) { //j代表的是第几个table
- var tableByDataSource = tables[j];
- var row = tableByDataSource.dataRange().row;
- var col = tableByDataSource.dataRange().col;
- var rowCount = tableByDataSource.dataRange().rowCount;
- var colCount = tableByDataSource.dataRange().colCount;
- console.log(row, col, rowCount, colCount);
- var arr = sheet.getArray(row-1,col,rowCount+1,colCount);
- sheet.tables.remove(tableByDataSource, GC.Spread.Sheets.Tables.TableRemoveOptions.keepData | GC.Spread.Sheets.Tables.TableRemoveOptions.keepStyle)
- sheet.setArray(row-1,col, arr);
- }
- }
- }
- }
复制代码 |