【发布时间】:2014-12-30 04:12:09
【问题描述】:
如何让这个脚本循环遍历目录中的所有文件?
我相信我可以按照我想要的方式保存文件,但我可以一次完成一个。
我正在学习 Powershell...
如何将工作簿 (excel 2010) 中的每个工作表保存为以下格式:文件名 + “-” + 工作表名称为 CSV?
- 在某些工作簿上,每个工作簿最多有 3 个工作表(可能更多...)
- 是否有最佳方式来执行此操作?
谢谢你,
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
Add-Type -AssemblyName Microsoft.Office.Interop.Excel
$excel = new-object -ComObject "Excel.Application";
$excel.DisplayAlerts=$True;
$excel.Visible =$false;
$wb = $excel.Workbooks.Open($scriptPath + "\1B1195.xlsb");
foreach($ws in $wb.Worksheets) {
if($ws.name -eq "OP10" -or $ws.name -eq "OP20" -or $ws.name -eq "OP30") {
Write-Host $ws.name;
$ws.SaveAs($scriptPath + "\" + $wb.name + "-" + $ws.name + ".csv", [Object] [Microsoft.Office.Interop.Excel.XlFileFormat]::xlCSVMSDOS);
}
}
$wb.close($False)
$excel.Quit();
[void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel);
【问题讨论】:
-
不要将问题用作输入此类信息的地方。如果其他用户遇到像您这样的问题,则更改您的问题会删除历史记录。如果需要,请在答案中添加感谢和其他信息作为评论。
标签: excel powershell