与Excel中的宏VBA我需要在excel文件中的1张转换日期。为此,我已经创建了一个脚本,但我有问题要在xml中正确生成日期我需要第一行标题,然后公式读取所有包含数据的行。宏VBA Excel创建XML文件日期
Sub createXML()
Sheets("Sheet1").Select
FullPath = baseDirectory & projectName & "\xmlBatch\inputTest.xml"
Set objStream = CreateObject("ADODB.Stream")
objStream.Charset = "iso-8859-1"
objStream.Open
objStream.WriteText ("<?xml version='1.0' encoding='UTF-8'?>" & vbLf)
objStream.WriteText ("<y:input xmlns:y='http://www.test.com/engine/3'>" & vbLf)
objStream.WriteText (" <y:datas>" & vbLf)
objStream.WriteText (" <y:instance yid='theGeneralData'>" & vbLf)
objStream.WriteText ("" & vbLf)
objStream.WriteText ("<language yid='LANG_en' />" & vbLf)
objStream.WriteText ("<client yclass='Client'>" & vbLf)
objStream.WriteText (" <firstName>" & Cells(1, 1).Text & "</firstName>" & vbLf)
objStream.WriteText (" <lastName>" & Cells(1, 2).Text & "</lastName>" & vbLf)
objStream.WriteText (" <age>" & Cells(1, 3).Text & "</age>" & vbLf)
objStream.WriteText (" <civility yid='" & toYID(Cells(1, 4).Text) & "' />" & vbLf)
objStream.WriteText ("</client>" & vbLf)
objStream.WriteText ("" & vbLf)
objStream.WriteText (" </y:instance>" & vbLf)
objStream.WriteText (" </y:datas>" & vbLf)
objStream.WriteText ("</y:input>" & vbLf)
objStream.SaveToFile FullPath, 2
objStream.Close
End Sub
Excel数据现在都是这种格式:
但我的输出现在是这样的:
> <?xml version='1.0' encoding='UTF-8'?>
<y:input xmlns:y='http://www.test.com/engine/3'>
<y:datas>
<y:instance yid='theGeneralData'>
<language yid='LANG_en' />
<client yclass='Client'>
<firstName>firstName</firstName>
<lastName>lastName</lastName>
<age>age</age>
<civility yid='CIVILITY' />
</client>
</y:instance>
</y:datas>
</y:input>
我们需要有这样的输出:
> <?xml version='1.0' encoding='UTF-8'?>
<y:input xmlns:y='http://www.test.com/engine/3'>
<y:datas>
<y:instance yid='theGeneralData'>
<language yid='LANG_en' />
<client yclass='Client'>
<firstName>1</firstName>
<lastName>1</lastName>
<age>1</age>
<civility yid='CIVILITY' />
</client>
<client yclass='Client'>
<firstName>2</firstName>
<lastName>2</lastName>
<age>2</age>
<civility yid='CIVILITY' />
</client>
<client yclass='Client'>
<firstName>3</firstName>
<lastName>3</lastName>
<age>3</age>
<civility yid='CIVILITY' />
</client>
</y:instance>
</y:datas>
</y:input>
什么问题?代码输出正确,据我所知。 – Andreas
我的问题是,我的脚本在XML文件数据不为客户端1,2,3 ..等创建一个新的标签正如你在第二个输出,我会得到的。我如何制作一个读取所有行的循环,同时为每行创建一个新标签 ? –
对不起,我现在没有时间回答,我必须回家。 – Andreas