如何防止在office js中将文本字符串转换为数字

发布于 2025-01-19 13:55:28 字数 133 浏览 4 评论 0原文

例如:101.01是字符串值,但是当数据添加到表中时,它将转换为101,01(欧洲数字格式),但在Excel中,它以文本格式显示为文本格式,但该值更改为(101.01 - > 101.01)) 。如何在办公室JS Excel附加组件中防止此操作

Ex: 101.01 is the string value but when data is added to the table it is converted to 101,01 (European number format) but in Excel it is displayed as text format, but the value is changed to (101.01 -> 101.01). How to prevent this in office js excel add-ins

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只想待在家 2025-01-26 13:55:28

@cybernetic.nomad 的建议是正确的。在 脚本中运行此函数Lab 确实会将值作为字符串而不是数字插入:

async function run() {
  await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();

    const range = sheet.getRange("A1");
    range.values = [["'101.01"]];

    await context.sync();
  });
}

请注意我如何在要插入的值字符串的开头插入撇号字符。

@cybernetic.nomad's suggestion is correct. Running this function in the Script Lab will indeed insert the value as a string, not as a number:

async function run() {
  await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getActiveWorksheet();

    const range = sheet.getRange("A1");
    range.values = [["'101.01"]];

    await context.sync();
  });
}

Note how I've inserted an apostrophe character at the beginning of the value string to be inserted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文