继续我的最后一个问题,我已经将我的工作表格式数据集转换为表格,但我遇到了另一个问题。
我有两个脚本,然后调用“转换”和“组合”。如果我单独运行它们,它们就可以工作。我要么将它们放入同一个脚本中,要么在一个流程中一起运行它们,这是我的期望。我在第 17 行遇到错误“我们无法运行脚本。请再试一次。 Office JS 错误:第 17 行:范围设置值:Le nombre de lignes ou de colonnes dans le tableau d'entrée ne correspond pas à la taille ou aux dimensions de la plage。 clientRequestId:b37f5819-3e01-4049-8ee9-630c341b2f79”
冲突在哪里?
转换
function main(workbook: ExcelScript.Workbook) {
//let selectedSheet = workbook.getActiveWorksheet();
workbook.getWorksheet('Feuil1')?.delete();
let worksheets = workbook.getWorksheets();
for (let i = 1; i < worksheets.length; i++) {
let selectedSheet = workbook.getWorksheets()[i];
selectedSheet.getRange("1:1").delete(ExcelScript.DeleteShiftDirection.up);
let newTable = workbook.addTable(selectedSheet.getRange("A1:AJ2"), true);
}
workbook.getWorksheet('Feuil1')?.delete();
}
结合
function main(workbook: ExcelScript.Workbook) {
// Delete the "Combined" worksheet, if it's present.
workbook.getWorksheet('Combined')?.delete();
workbook.getWorksheet('Feuil1')?.delete();
// Create a new worksheet named "Combined" for the combined table.
const newSheet = workbook.addWorksheet('Combined');
// Get the header values for the first table in the workbook.
// This also saves the table list before we add the new, combined table.
const tables = workbook.getTables();
const headerValues = tables[1].getHeaderRowRange().getTexts();
console.log(headerValues);
// Copy the headers on a new worksheet to an equal-sized range.
const targetRange = newSheet.getRange('A1').getResizedRange(headerValues.length-1, headerValues[0].length-1);
//targetRange.setValues(headerValues);
// Add the data from each table in the workbook to the new table.
const combinedTable = newSheet.addTable(targetRange.getAddress(), true);
for (let table of tables) {
let dataValues = table.getRangeBetweenHeaderAndTotal().getTexts();
let rowCount = table.getRowCount();
// If the table is not empty, add its rows to the combined table.
if (rowCount > 0) {
combinedTable.addRows(0, dataValues);
}
}
}