請賜教,謝謝。
1.用記事本新增一個文字檔,並把它存到C槽底下,命名為 csv2xml.vbs
裡面的內容如下:
<pre class="c" name="code">
Dim objStartFile,objEndFile,objFSO,objFile,objFile2,oi
objStartFile = Wscript.Arguments.Item(0)
objEndFile=Replace(objStartFile,".csv","") & ".xml"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile( objStartFile, 1)
Set objFile2 = objFSO.OpenTextFile(objEndFile, 2,true)
objFile2.writeLine "<?xml version="&chr(34)&"1.0"&chr(34)&" encoding="&chr(34)&"UTF-8"&chr(34)&"?>"
objFile2.writeLine "<list>"
oi=0
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If oi>0 Then
objFile2.writeLine chr(9)&"<my_rec>"
myArray = Split(strLine,",")
objFile2.writeLine chr(9)&chr(9)&"<id>"&myArray(0)&"</id>"
objFile2.writeLine chr(9)&chr(9)&"<title>"&myArray(1)&"</title>"
objFile2.writeLine chr(9)&chr(9)&"<pic>"&myArray(2)&"</pic>"
objFile2.writeLine chr(9)&"</my_rec>"
End If
oi=oi+1
Loop
objFile2.writeLine "</list>"
objFile.Close
objFile2.Close
2.把你要轉換的csv檔放到C槽底下,例如 test.csv
3.開啟DOS畫面,在C:\底下鍵入
<pre class="c" name="code">csv2xml.vbs test.csv<enter>
你要的test.xml就會出來了~
請善用 Google 大神查詢 csv to xml
馬上就跳出答案啦
http://csv2xml.sourceforge.net/