我需要将excel工作表(.xlsx)转换为“ XML文档”(.xlsx)文件类型。目前,我正在手动打开每个工作表并将其另存为“ XML Spreadsheet 2003”,我正在寻找Powershell脚本或excel-VBA宏来减少手动工作。
下面的代码将.xlsx文件转换为.xml
$Path = "C:\dev\"
$dev = Get-ChildItem -Path "$Path*" -Include "*.xls","*.xlsx"
If ($dev.Count -gt 0) {
Write-Host "Excel files found:" $dev.Count
Foreach ($File in $dev) {
$XLXMLSpreadsheet = 46
$Excel = New-Object -ComObject Excel.Application
$WorkBook = $Excel.Workbooks.Open($File.FullName)
$Destination = $Path + $File.BaseName + ".xml"
$WorkBook.SaveAs($Destination, $XLXMLSpreadsheet)
$Excel.Quit()
}
Stop-Process -Name EXCEL
}
Else {Write-Warning "Could not find any excel files. Please ensure this path is correct and
the files exist:`n'$Path'"}
此代码convert.xml文件为“ XM文件”,但我的要求是转换为“ XML文档”文件类型。 我尝试寻找“ XML Spreadsheet 2003”格式的excel保存值,但是没有运气。 将.xlsx文件转换为.xml(“ XML文档”)的任何想法都会有很大帮助。