备注
桌面流提供调整 Excel 工作表中的列/行大小操作,以方便调整 Excel 列和行的大小。 本文介绍了使用脚本调整 Excel 列和行大小的另一种方法。
Excel 中的自动调整功能使用户能够调整工作表中单元格的大小以适应不同大小的数据,而无需手动更改列宽和行高。
使用 Power Automate 中的脚本自动调整 Excel 列:
使用设置变量操作创建一个新变量,其中包含要操作的 Excel 文件的路径。 在此示例中,此变量被命名为 ExcelFile。
部署运行 VBScript 操作并填充以下代码。 在运行流之前,将 SheetName 占位符替换为要自动调整的工作表的名称或包含名称的变量。
'Opens the Excel file' Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("%ExcelFile%") objExcel.Application.Visible = True 'Selects the specified sheet' Set objSheet = objWorkbook.Sheets("SheetName") 'Autofits the columns of the sheet'S for col=1 to 19 objSheet.columns(col).AutoFit() next 'Saves and closes the Excel file' objWorkbook.Save objWorkbook.Close SaveChanges = True