嗯嗯,老大费心了!
如下,下面是我推断的理由(完全可能是错的),但这无关紧要,你们能修复,提供一个保持一致的方法就好。
- document.getElementById('export').onclick = function(){
- const sheet = spread.getActiveSheet();
- // 开始尝试导出前重置 range 来修复合并问题(假设导出后是先 colHeader 后 viewport)
- // 1.先清空已定义的合并
- const fullRange = new GC.Spread.Sheets.Range(-1, -1, -1, -1);
- sheet.autoMerge(fullRange, GC.Spread.Sheets.AutoMerge.AutoMergeDirection.none);
- // 2. 定义colHeader合并范围(<b>实际上应用到了导出excel的第3~4行</b>)
- const headerRange = new GC.Spread.Sheets.Range(0, 0, 2, 10);
- sheet.autoMerge(headerRange, GC.Spread.Sheets.AutoMerge.AutoMergeDirection.rowColumn, GC.Spread.Sheets.AutoMerge.AutoMergeMode.restricted, GC.Spread.Sheets.SheetArea.viewport);
- // 3. 定义viewport合并范围(<b>实际上应用到了导出excel的第5+行</b>)
- const viewrRange = new GC.Spread.Sheets.Range(2, 0, 10, 10);
- sheet.autoMerge(viewrRange, GC.Spread.Sheets.AutoMerge.AutoMergeDirection.column, GC.Spread.Sheets.AutoMerge.AutoMergeMode.restricted, GC.Spread.Sheets.SheetArea.viewport);
- // 通过2,3对应实际导出 excel 导出后看到的效果,猜测是先 viewport 后 插入(比如 insertAtRow(0)) colHeader 的
-
- var json = spread.toJSON({includeAutoMergedCells:true,columnHeadersAsFrozenRows:true});
- // here is excel IO API
- excelIo.save(json, function (blob) {
- saveAs(blob, "export.xlsx");
- }, function (e) {
- // process error
- console.log(e);
- });
- };
复制代码
|