2

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.

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

0

The general process of exporting an Excel sheet to XML is described here. You could record this as a macro and then adopt that into PowerShell. You could also hand-craft the XML from the data in the sheet(s). Either way you're going to need some kind of definition of how the data from the Excel sheet should be mapped into the XML structure.

1 Comment

Thanks for your help :) I will try that.Nevertheless i guess there is a way to actually save a file as XML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.