【问题标题】:Copy Excel OneDrive table to an specific cell on another Excel OneDrive table (Power Automate)将 Excel OneDrive 表复制到另一个 Excel OneDrive 表上的特定单元格 (Power Automate)
【发布时间】:2021-07-16 02:08:24
【问题描述】:

我需要从一个 Excel 工作表中复制数据,然后使用 Power Automated + Office 脚本将数据(仅限值)粘贴到另一个工作表上

我开始使用下面链接中的答案创建流程。

Power Automate: Copy Excel OneDrive table to the bottom of another Excel OneDrive table

问题是我没有理解第二个脚本,所以我无法将它修改为我需要的(工作簿末尾的那个粘贴)

链接上的脚本

For Run script I have

function main(workbook: ExcelScript.Workbook) {
  const sheet = workbook.getWorksheets()[0];
  let lastRow = sheet.getUsedRange(true).getLastCell().getRowIndex() + 1;
  let rng = "A3:P" + lastRow
  let tableTest = sheet.getRange(rng).getValues();
  console.log(tableTest);
}
Then under Compose

@{outputs('Run_script')?['body']?['Logs'][0]}
Then Initialize the "RemoveString" variable

@{split(outputs('Compose'),' ')[0]}
Then Initialize the "NewString" variable

@{replace(outputs('Compose'),variables('RemoveString'),'')}
Then Run Script 2 and add "NewString" as the parameter.

function main(workbook: ExcelScript.Workbook, rangeTest: string) {
  let table = workbook.getTable("BacklogTable");
  let str = rangeTest;
  let testerTest = JSON.parse(str);
  table.addRows(null, testerTest);
}

RemoveString 的原因是从输出中删除日期和时间戳

【问题讨论】:

  • 嘿,我回答了这个问题,你想做什么不同的事情?你收到错误或什么?还是要将其添加到不是表格的单元格中?
  • 我对办公脚本知之甚少,但如果它是一个表格,这不是问题,但我需要将信息粘贴到特定单元格并替换信息
  • 好的,您希望它粘贴到哪个单元格中?
  • 从 A7 开始,之前复制的表格范围(粘贴为数字)
  • 这回答了你的问题吗?

标签: onedrive power-automate excel-online office-scripts


【解决方案1】:

这需要一些不同的工作流程。

运行脚本

function main(workbook: ExcelScript.Workbook) {
  const sheet = workbook.getWorksheets()[0];
  let lastRow = sheet.getUsedRange(true).getLastCell().getRowIndex() + 1;
  let rng = "A2:C" + lastRow
  let tableTest = sheet.getRange(rng).getValues();
  console.log(tableTest);
  console.log(tableTest.length)
}

作曲

@{outputs('Run_script')?['body']?['Logs'][0]}

作曲 2

@{outputs('Run_script')?['body']?['Logs'][1]}

删除字符串

@{split(outputs('Compose'),' ')[0]}

新字符串

@{replace(outputs('Compose'),variables('RemoveString'),'')}

删除字符串2

@{split(outputs('Compose_2'),' ')[0]}

新字符串2

@{int(replace(outputs('Compose_2'),variables('RemoveString2'),''))}

数量

@{int(variables('NewString2'))}

运行脚本 2

function main(workbook: ExcelScript.Workbook, rangeTest: string, length: number) {
  let str = rangeTest;
  const arr = JSON.parse(str);
  let sheet = workbook.getWorksheet("Sheet2");
  let rng = "A7:C" + (6 + length); //Change C to whichever column you want to end on
  sheet.getRange(rng).setValues(arr);
  sheet.getRange(rng).setNumberFormatLocal("0.00");
}

【讨论】:

  • 谢谢!!!它肯定回答了我的问题!这个周末我会试试这个流程,告诉你它是否有效!
【解决方案2】:

我可能没有正确遵循这一点,但您也可以返回值并将它们传递给 Power Automate 中的另一个连接器。这是一些关于如何使用 Office 脚本返回值的 documentation。此外,下面是一个带有参数和 number 类型返回值的示例脚本。通过返回值而不是 console.logging 它们,您无需在 Flow 步骤中删除任何输出。如果您有任何问题,请告诉我!

function main(
  workbook: ExcelScript.Workbook,
  issueId: string,
  issueTitle: string): number {
  // Get the "GitHub" worksheet.
  let worksheet = workbook.getWorksheet("GitHub");

  // Get the first table in this worksheet, which contains the table of GitHub issues.
  let issueTable = worksheet.getTables()[0];

  // Add the issue ID and issue title as a row.
  issueTable.addRow(-1, [issueId, issueTitle]);

  // Return the number of rows in the table, which represents how many issues are assigned to this user.
  return issueTable.getRangeBetweenHeaderAndTotal().getRowCount();
}

【讨论】:

    猜你喜欢
    • 2021-07-02
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多