如何将Excel文件(xlsx)批量转换为csv?我试过了
$source = 'C:\path\to\file'
Get-ChildItem $source '*.xlsx' | Rename-Item -NewName { $_.Name -replace '\.xlsx','.csv' }
但是csvs是不可读的。理想情况下,我希望能够从每张纸上制作一张csv(所以我不需要在转换之前手动分开它们。)
感谢。
答案 0 :(得分:1)
这是我发现/得到的:
$source = 'C:\path\to\file'
Function ExcelCSV ($File)
{
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $false
$Excel.DisplayAlerts = $false
$wb = $Excel.Workbooks.Open($File.FullName)
foreach ($ws in $wb.Worksheets)
{
$ws.SaveAs(($Files.FullName -replace ".xlsx$","") + ".csv", 6)
}
$wb = $Excel.Workbooks.Close()
$Excel.Quit()
}
Foreach ($Files in (Get-ChildItem -Path $source -Filter "*.xlsx"))
{
ExcelCSV($Files)
}