将Excel工作表另存为xml会在某些行周围添加引号

时间:2016-09-01 11:07:08

标签: xml excel vba excel-vba

我有一个包含xml脚本的工作表,大约15列乘70000行。我想将此数据保存到.xml文件。我正在使用的当前代码是:

Sub saveXML()
    Dim GenerateSheet As Worksheet
    Set GenerateSheet = ThisWorkbook.Sheets("TestCase-")
    GenerateSheet.SaveAs Filename:="C:\Users\" & "TestCase-" + Format(Now(), "YYYYMMDD") & ".xml", FileFormat:=xlTextWindows
End Sub

这会将其保存为.xml文件,但似乎在文件中的随机行周围添加了引号,这会破坏xml文件。

"<con:testCase xmlns:con=""http://eviware.com/soapui/config"" failOnError=""true"" failTestCaseOnErrors=""false"" keepSession=""false"" maxResults=""0"" name=""name"" searchProperties=""true"">"                                                                              
<con:settings/>                                                                             
"<con:testStep type=""request""  name=""TestStep_0001"">"                                                                               
<con:settings/>                                                                             
"<con:config xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:type=""con:RequestStep"">"                                                                             
<con:interface>QuoteService</con:interface>                                                                             
<con:operation>NewRate</con:operation>                                                                              
"<con:request name=""NewRate - Request 1"" outgoingWss="""" incomingWss="""" timeout="""" sslKeystore="""" useWsAddressing=""true"" useWsReliableMessaging=""false"" wssPasswordType="""">"                                                                             
<con:settings>  

在工作表中,任何行周围都没有引号。

如何控制或阻止此行为?

2 个答案:

答案 0 :(得分:0)

引用的代码无效。 (他们错过了结束标签并且不是自动关闭)。在每个引用标记的末尾添加/,以使它们自动关闭。

例子(注意结尾附近的“/”)

<con:request name="NewRate - Request 1" outgoingWss="" incomingWss="" timeout="" sslKeystore="" useWsAddressing="true" useWsReliableMessaging="false" wssPasswordType=""/>

答案 1 :(得分:0)

我在其他类型的文件中看到了类似的结果,其中包含转义引号(“)的行被引号本身包围。

我想说在保存的文件上运行某种形式的后期处理,或者根据文件创建一个XML地图:

ActiveWorkbook.XmlMaps.Add("[path to your file]", "[rootname]").Name = "[name of map]"

然后您应该能够将该文件保存为XML文件,但我还没有对此进行测试。

相关问题