I recorded a script, to adjust column widths. But When I run the macro, the column widths are not adjusted correctly. What is wrong with my script?
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Clear ExcelScript.ClearApplyTo.contents from range 1:7 on selectedSheet
selectedSheet.getRange("1:7").clear(ExcelScript.ClearApplyTo.contents);
// Set height of row(s) at range 1:7 on selectedSheet to 30
selectedSheet.getRange("1:7").getFormat().setRowHeight(30);
// Set width of column(s) at range A:B on selectedSheet to 12
selectedSheet.getRange("A:B").getFormat().setColumnWidth(12);
// Set width of column(s) at range C:C on selectedSheet to 65
selectedSheet.getRange("C:C").getFormat().setColumnWidth(65);
// Auto fit the columns of range E:E on selectedSheet
selectedSheet.getRange("E:E").getFormat().autofitColumns();
// Set width of column(s) at range I:J on selectedSheet to 18
selectedSheet.getRange("I:J").getFormat().setColumnWidth(18);
// Delete range K:U on selectedSheet
selectedSheet.getRange("K:U").delete(ExcelScript.DeleteShiftDirection.left);
// Delete range D:D on selectedSheet
selectedSheet.getRange("D:D").delete(ExcelScript.DeleteShiftDirection.left);
// Delete range E:G on selectedSheet
selectedSheet.getRange("E:G").delete(ExcelScript.DeleteShiftDirection.left);
// Set range D9:F9 on selectedSheet
selectedSheet.getRange("D9:F9").setValues([["VPPS","SDC","FSU"]]);
}
function main(workbook: ExcelScript.Workbook) {
let selectedSheet = workbook.getActiveWorksheet();
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Insert at range 1:1 on selectedSheet, move existing cells down
selectedSheet.getRange("1:1").insert(ExcelScript.InsertShiftDirection.down);
// Clear ExcelScript.ClearApplyTo.contents from range 1:7 on selectedSheet
selectedSheet.getRange("1:7").clear(ExcelScript.ClearApplyTo.contents);
// Set height of row(s) at range 1:7 on selectedSheet to 30
selectedSheet.getRange("1:7").getFormat().setRowHeight(30);
// Set width of column(s) at range A:B on selectedSheet to 12
selectedSheet.getRange("A:B").getFormat().setColumnWidth(12);
// Set width of column(s) at range C:C on selectedSheet to 65
selectedSheet.getRange("C:C").getFormat().setColumnWidth(65);
// Auto fit the columns of range E:E on selectedSheet
selectedSheet.getRange("E:E").getFormat().autofitColumns();
// Set width of column(s) at range I:J on selectedSheet to 18
selectedSheet.getRange("I:J").getFormat().setColumnWidth(18);
// Delete range K:U on selectedSheet
selectedSheet.getRange("K:U").delete(ExcelScript.DeleteShiftDirection.left);
// Delete range D:D on selectedSheet
selectedSheet.getRange("D:D").delete(ExcelScript.DeleteShiftDirection.left);
// Delete range E:G on selectedSheet
selectedSheet.getRange("E:G").delete(ExcelScript.DeleteShiftDirection.left);
// Set range D9:F9 on selectedSheet
selectedSheet.getRange("D9:F9").setValues([["VPPS","SDC","FSU"]]);
}