首页 > 解决方案 > Excel 脚本超时错误 - 可能的 JSON 问题?

问题描述

我有一个脚本设置可以在流程中自动运行。但是,我注意到如果循环超过 4,000 行,脚本就会出错。

我最初并没有创建脚本,所以我试图维护它并扩展它可以处理的行数。它基本上是复制和循环多行。这是脚本:

"function main(workbook: ExcelScript.Workbook, rangeTest: string)
{
  let newSheet = workbook.getWorksheet("Main Table")
  let tableName = newSheet.getTable("MainTable");
  let col1;
  let col2;
  let col3;
  let col4;
  let col5;
  let col6;
  let col7;
  let col8;
  let col9;
  let col10;
  let col11;
  let col12;
  let col13;
  let col14;

  let str = rangeTest;
  let testerTest = JSON.parse(str);
  console.log(testerTest.length);

  for (let i = 1; i < testerTest.length; i++) {
    col1 = testerTest[i][1]; //Col A
    col2 = testerTest[i][2]; //Col B
    col3 = testerTest[i][15]; //Col C
    col4 = testerTest[i][4]; //Col D
    col5 = testerTest[i][5]; //Col E
    col6 = testerTest[i][13]; //Col F
    col7 = testerTest[i][10]; //Col G
    col8 = testerTest[i][6]; //Col H
    col9 = testerTest[i][7]; //Col I
    col10 = testerTest[i][19]; //Col J 
    col11 = testerTest[i][8]; //Col K 
    col12 = testerTest[i][9]; //Col L
    col13 = testerTest[i][11]; //Col M
    col14 = testerTest[i][12]; //Col N
    tableName.addRow(null, [col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12, col13, col14]);
  }

}"

来自流的错误消息

来自 Flow 的成功消息

上面的两个图像显示了当流/脚本在超过 4000 行时失败以及当流/脚本在 4000 行以下成功时收到的消息。

有什么方法可以修改脚本、流程、JSON 或任何东西以允许该脚本在超过 4000 行的文件上运行?

标签: jsonexceltypescriptpower-automate

解决方案


推荐阅读