【发布时间】:2016-08-25 11:19:51
【问题描述】:
我需要这方面的帮助....
我有包含数据的 Excel 文件。
我需要使用 VB.NET 中的 XML Literals 将其导出到 XMLfile
结果我需要一些 XML 文件:
<?xml version="1.0" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://...">
<soapenv:Header/>
<soapenv:Body xmlns:wsu="http://....xsd">
<Header>
<Verb>cancel</Verb>
</Header>
<Request>
<ID>VALUE-1</ID>
<ID>VALUE-2</ID>
<ID>VALUE-3</ID>
......
</Request>
</soapenv:Body>
</soapenv:Envelope>
其中 VALUE-1、VALUE-2、....等等 - 我从具有 Ron Numer i 且列 Number = 2 的单元格中获取它们。 在循环中的 VB.NET 中,我这样做了:
While Not this condition
While Not (String.IsNullOrEmpty(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet.Cells(iRow, 1).Value))
'Check next condition with IF
If LCase(Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet.Cells(iRow, 25).Value) = "y" Then
'Add XElement object into another one XML Element from main XDocument
objRequestCANCEL.Add(objIDCANCEL)
'Add Value for this new Element
objIDCANCEL.Value = Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet.Cells(iRow, 2).Value
End If
'Go to next Row and do the same - add XELement if condition is OK here
iRow = iRow + 1
End While
这里 objIDCANCEL 作为主 XDocument 中的 XElement 在这种情况下,我使用了 XElements,如变量。但现在我需要像创建文档这样的东西,没有像这样的变量:
Dim XDoc As XDocument = <?xml version="1.0" standalone="no"?>
<soapenv:Envelope xmlns:soapenv="http://...">
<soapenv:Header/>
<soapenv:Body xmlns:wsu="http://....xsd">
<Header>
<Verb>create</Verb>
<ID><%= varValue %> </ID>
.....HERE I NEED ADD IN LOOP ALL VALUES FROM ALL ROWS IN EXCEL FILE.....
</Header>
<Request>
</Request>
</RequestMessage>
</soapenv:Body>
</soapenv:Envelope>
请写信给我,我怎样才能在这里重写这个循环?
【问题讨论】:
-
你不能在里面放任何循环语句,你只能使用 LINQ
From .. Select表达式。 -
但是在我的情况下,我的情况看起来像 LINQ 而不是 Loop?
标签: xml vb.net xml-literals