办公脚本以复制一个电子表格的数据并添加到表格
我正在尝试使用Office脚本设置电源自动流量,以将数据从多个电子表格传输到一个主表。流程是由放入文件夹中的文件触发的,然后应该运行两个脚本,一个是从新表中获取数据,另一个将数据传输到主电子表格。我的问题是后一个脚本。
function main(workbook: ExcelScript.Workbook) : (number | string | boolean)[][] {
// Get the active worksheet
let target_ws = workbook.getActiveWorksheet();
// Get the range with the data
let tbl_range = target_ws.getUsedRange()
.getOffsetRange(6, 2)
.getResizedRange(-6, -5);
// Get date range
let date_range_string = target_ws.getRange("H2").getValue().toString();
let start_date = date_range_string.split(" - ")[0];
let end_date = date_range_string.split(" - ")[1];
// Get the data range
let table_data = tbl_range.getValues();
let rowsToMoveValues: (number | string | boolean)[][] = [];
// Add the start date to each row
if (start_date === end_date) {
for (let i = 0; i < table_data.length; i++) {
table_data[i][0] = start_date;
rowsToMoveValues.push(table_data[i]);
}
}
return rowsToMoveValues;
}
这可以获得数据,而且似乎运行良好。
function main(workbook: ExcelScript.Workbook, new_data: string[][])
{
// Get the charity table
let master_table = workbook.getTable('Master_Table');
// Add new files to the table
master_table.addRows(-1, new_data);
}
这个人一直失败,但以一种怪异的方式失败。它将我的输出从第一个脚本中吸收并将其转换为一个长字符串。 ” [[3/31/2022“,”“,6957.16,75840],[“ 3/31/2022”,541,20.7,198],[“ 3/31/2022”,1306,1,1,113],。 ..ETC。”而不是将其视为数组并将数据添加到列中。最初,主表中有四列,但由于输入数组的大小不匹配,因此失败了。如果我告诉Power Automate使用结果[0]再次将其视为一个字符串,但是如果我将其递给它,则它会显示这样的结果:
[
[
[
[
"3/31/2022",
"",
6957.16,
75840
],
[
"3/31/2022",
541,
20.7,
198
],
[
"3/31/2022",
1306,
1,
113
], etc.
我很奇怪地怀疑输出上有一组括号太多,我不知道为什么,而且我不知道该如何解决。当我将结果传递给第二个功能时,表中有4列,它失败了。当我通过主表中只有一个列通过结果时,它可以工作,但将所有内容都放在一行和报价中。
感谢您的帮助!
I'm trying to set up a Power Automate flow using office scripts to transfer data from multiple spreadsheets to one master table. The flow is triggered by a file being put in a folder, then it's supposed to run two scripts, one to get the data from the new sheet, and another to transfer that data to the master spreadsheet. My issue is the latter script.
function main(workbook: ExcelScript.Workbook) : (number | string | boolean)[][] {
// Get the active worksheet
let target_ws = workbook.getActiveWorksheet();
// Get the range with the data
let tbl_range = target_ws.getUsedRange()
.getOffsetRange(6, 2)
.getResizedRange(-6, -5);
// Get date range
let date_range_string = target_ws.getRange("H2").getValue().toString();
let start_date = date_range_string.split(" - ")[0];
let end_date = date_range_string.split(" - ")[1];
// Get the data range
let table_data = tbl_range.getValues();
let rowsToMoveValues: (number | string | boolean)[][] = [];
// Add the start date to each row
if (start_date === end_date) {
for (let i = 0; i < table_data.length; i++) {
table_data[i][0] = start_date;
rowsToMoveValues.push(table_data[i]);
}
}
return rowsToMoveValues;
}
That gets the data, and it seems to be working fine.
function main(workbook: ExcelScript.Workbook, new_data: string[][])
{
// Get the charity table
let master_table = workbook.getTable('Master_Table');
// Add new files to the table
master_table.addRows(-1, new_data);
}
This one keeps failing, but it fails in a weird way. It's taking my output from the first script and converting it into one long string. "[["3/31/2022","",6957.16,75840],["3/31/2022",541,20.7,198],["3/31/2022",1306,1,113],...etc." instead of treating it as an array and adding the data in columns. Originally there were four columns in the master table, but that failed because the size of the input array didn't match. If I tell Power Automate to use result[0] it again treats it as a single string, but if I hand it just the result it displays like this:
[
[
[
[
"3/31/2022",
"",
6957.16,
75840
],
[
"3/31/2022",
541,
20.7,
198
],
[
"3/31/2022",
1306,
1,
113
], etc.
I have a weird suspicion that there's one too many sets of brackets on the output, and I don't know why, and I don't know how to fix it. When I passed the result to the second function with 4 columns in the table, it failed. When I passed the result with only one column in the master table, it worked, but put everything on one line and in quotations.
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论