在powershell中将XML转换为xlsx [英] Convert XML to xlsx in powershell

查看:43
本文介绍了在powershell中将XML转换为xlsx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上找到了一些 powershell 命令,可以将 xlsx 文件转换为 xml 文件.这很好用,但是我得到的 xml 会被稍微操纵,然后我需要将它转换回标准的 xlsx 文件.

I found some powershell command online to convert an xlsx file to an xml file. This works great, but the xml I am getting will be manipulated slightly, and after that I need to convert it back into a standard xlsx file.

使用从以下命令生成的 xml,如何将其转换回 xlsx 文件?

With an xml generated from the below commands, how could I convert it back to an xlsx file?

谢谢!

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

推荐答案

只需打开 xml 文件并保存即可.

Just open the xml file and save it.

xlsx 文件的格式代码为 51,根据 https://msdn.microsoft.com/en-us/vba/excel-vba/articles/xlfileformat-enumeration-excel

The Format code for an xlsx file is 51, as per https://msdn.microsoft.com/en-us/vba/excel-vba/articles/xlfileformat-enumeration-excel

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

这篇关于在powershell中将XML转换为xlsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆