Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

复制腾讯文档表格会现格式错误 #139

Open
1 of 8 tasks
7hens opened this issue Sep 24, 2024 · 2 comments
Open
1 of 8 tasks

复制腾讯文档表格会现格式错误 #139

7hens opened this issue Sep 24, 2024 · 2 comments

Comments

@7hens
Copy link

7hens commented Sep 24, 2024

问题描述

腾讯文档复制 excel 表格会出现格式错误。

如针对以下表格:

H1 H2
A
B
C

复制之后的的文本为:

H1 H2\nA\nB C

将该文本复制到 excel 表格后,会呈现下面的样式:

H1 H2
A
B C

项目所属

  • Copy
  • Force Copy
  • Copy Currency
  • Site Director
  • Captcha
  • Expansion
  • Completion
  • Unknown

相关链接

https://docs.qq.com/sheet/DR1p2a2lqTWRRSklE?tab=BB08J2

预期表现

见问题描述。

解决方案

相关代码:

https://github.com/WindrunnerMax/TKScript/blob/master/packages/copy/src/modules/docqq.ts

          if (selection) {
            const text = [];
            const { startColIndex, startRowIndex, endColIndex, endRowIndex } = selection;
            for (let i = startRowIndex; i <= endRowIndex; i++) {
              for (let k = startColIndex; k <= endColIndex; k++) {
                const cell = SpreadsheetApp.workbook.activeSheet.getCellDataAtPosition(i, k);
                if (!cell)
                  continue;
                text.push(" ", ((_a = cell.formattedValue) == null ? void 0 : _a.value) || cell.value || "");
              }
              i !== endRowIndex && text.push("\n");
            }
            const str = text.join("");
            return /^\s*$/.test(str) ? "" : str;
          }

问题代码:

text.push(" ", ((_a = cell.formattedValue) == null ? void 0 : _a.value) || cell.value || "");

修改后的代码:

text.push("\t", (((_a = cell.formattedValue) == null ? void 0 : _a.value) || cell.value || "").replace(/\n/g, '\\n'));

经过上面的修改,得到的结果为:

H1 H2
A\nB C

遗留问题:单元格内的换行被转换成了 \\n

@WindRunnerMax
Copy link
Owner

没太看懂,你的意思是已经解决了问题吗,直接提个pr就好

@WindRunnerMax
Copy link
Owner

WindRunnerMax commented Sep 24, 2024

另外替换这个 \n\\n 没有必要吧,原本不就是带着换行

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants