與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