简体   繁体   English

使用PowerShell将Excel文件保存为XML

[英]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. 我目前正在powershell中编写一个脚本,通过文件树递归搜索XLS文件。 I'd like to save all the files to xml to be able to read through them and change data as needed. 我想将所有文件保存到xml,以便能够读取它们并根据需要更改数据。

Is there anyway to save Excel files as XML with Powershell ? 有没有用Powershell将Excel文件保存为XML?

Thanks for your help ! 谢谢你的帮助 !

---- Update ---- ----更新----

I found a script here that basically creates an excel file and save it as an xml. 我在这里找到了一个基本创建excel文件并将其保存为xml的脚本。

Using the same principle i did the following, which basically open a file and save it to xml: 使用相同的原理,我做了以下,基本上打开一个文件并将其保存到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. 但我不知道第二个saveas()参数。

I found a script here that basically converts create an excel file and save it as an xml. 我在这里找到一个脚本,基本上转换创建一个excel文件并将其保存为xml。

Using the same principle i did the following, which basically open a file and save it to xml: 使用相同的原理,我做了以下,基本上打开一个文件并将其保存到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. 但我不知道第二个saveas()参数。

The general process of exporting an Excel sheet to XML is described here . 此处描述将Excel工作表导出为XML的一般过程。 You could record this as a macro and then adopt that into PowerShell. 您可以将其记录为宏,然后将其应用到PowerShell中。 You could also hand-craft the XML from the data in the sheet(s). 您还可以从工作表中的数据手工制作XML。 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. 无论哪种方式,您都需要某种定义,如何将Excel表格中的数据映射到XML结构中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM