Search code examples
xmlexcelpowershellpowershell-3.0

Saving Excel File as XML with PowerShell


I'm currently writing a script in powershell that searches for XLS files recursivly through a file tree. I'd like to save all the files to xml to be able to read through them and change data as needed.

Is there anyway to save Excel files as XML with Powershell ?

Thanks for your help !

---- Update ----

I found a script here that creates an excel file and save it as an xml.

Using the same principle i did the following, which basically open a file and save it to xml:

$xlXMLSpreadsheet = 46

$Excel = New-Object -Com Excel.Application
 
$WorkBook = $Excel.Workbooks.Open("c:\Test.xlsx")
 
$WorkBook.SaveAs("c:\Test.xml", $xlXMLSpreadsheet)
 
$Excel.Quit()

And it works really well. But i wasnt aware of the second saveas() parameter.


Solution

  • I found a script here that create an excel file and save it as an xml.

    Using the same principle i did the following, which basically open a file and save it to xml:

    $xlXMLSpreadsheet = 46
    
    $Excel = New-Object -Com Excel.Application
     
    $WorkBook = $Excel.Workbooks.Open("c:\Test.xlsx")
     
    $WorkBook.SaveAs("c:\Test.xml", $xlXMLSpreadsheet)
     
    $Excel.Quit()
    

    And it works really well. But i wasnt aware of the second saveas() parameter.