找回密码
 立即注册

QQ登录

只需一步,快速开始

z9961

注册会员

3

主题

3

帖子

34

积分

注册会员

积分
34

微信认证勋章

  • 964

    金币

  • 3

    主题

  • 3

    帖子

最新发帖

[已处理] V14 导出excel报错

z9961
注册会员   /  发表于:2021-8-30 16:22  /   查看:1426  /  回复:2
本帖最后由 Lynn.Dou 于 2021-9-13 10:43 编辑

image.png683796996.png

1.rar

24.04 KB, 下载次数: 23

2 个回复

倒序浏览
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-9-3 17:45:24
推荐
经调研,原因如下:
1、sheet1中有一张表,名字叫“ Table1 ”,sheet2有一张表,名字也叫“ Table1 ”。
2、SpreadJS 允许不同的表可以具有相同的表名,但是Excel不允许。
Excel会将第二个同名table的displayName重命名为“ Table1_1 ”


有个解决方案您可以参考下:
在执行workbook.fromJSON前,执行下方代码:
  1. // usage
  2. repairTableNames(spreadJSON);
  3. spread.fromJSON(spreadJSON);

  4. function repairTableNames(json) {
  5.     // this manager for rename the tables with table id which has the same table name
  6.     var nameManager = {};
  7.     var sheets = json.sheets;
  8.     for (var sheetName in sheets) {
  9.         var sheet = sheets[sheetName];
  10.         var tables = sheet.tables;
  11.         if (tables) {
  12.             for (var i = 0; i < tables.length; i ++) {
  13.                 var table = tables[i];
  14.                 var tableName = table.name;
  15.                 if (typeof nameManager[tableName] === "number") {
  16.                     // In this branch, this table has same name with previous table
  17.                     // Just increase the table id, then rename with this id
  18.                     nameManager[tableName] ++;
  19.                     table.name = tableName + "_" + nameManager[tableName];
  20.                 } else {
  21.                     // In this branch, this table name never appeared in name manager
  22.                     nameManager[tableName] = 0;
  23.                 }
  24.             }
  25.         }
  26.     }   
  27. }
复制代码



回复 使用道具 举报
Lynn.Dou讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2021-8-30 17:29:31
沙发
本帖最后由 Lynn.Dou 于 2021-9-13 10:43 编辑

您好,
问题已复现,
已将此问题记录下来,待有进展会在本贴更新。
本贴先做保留处理。(SJS-9918)
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部