I have a vbscript code, where I convert from xml to xlsx. However, when converting it duplicates the information and takes the order of the columns. How do I reverse or adjust? Because I'm not able to format correctly. If you use excel and open it by hand and convert to xlsx it is correct.
This is my vbs code:
Dim xlApp, xlWkb, SourceFolder, TargetFolder, file
Set xlApp = CreateObject ("excel.application")
Set fs = CreateObject ("Scripting.FileSystemObject")
Const ForWriting = 2
Const TristateTrue = -1
Const xlNormal = 51
SourceFolder = "C: Users Convex Documents MICHAEL XML"
TargetFolder = "C: Users Convex Documents MICHAEL XLS"
xlApp.Visible = false
for each file in fs.GetFolder (SourceFolder) .files
Set xlWkb = xlApp.Workbooks.Open (file)
BaseName = fs.getbasename (file)
FullTargetPath = TargetFolder & "" & BaseName & ".xlsx"
xlWkb.SaveAs FullTargetPath, xlNormal
xlWkb.close
next
'Uncomment this line to delete the source file
'fs.DeleteFile ("C: xml-to-xls xml *. xml")
Set xlWkb = Nothing
Set xlApp = Nothing
Set fs = Nothing
This is the xml:
<? xml version = "1.0" encoding = "utf-8"?>
<Transaction>
<list>
<registers>
<matricula> 5 </matricula>
<name> ANGEL EDUARDO TRIGUEROS CISNEROS </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 9 </matricula>
<name> MARCO AURELIO CARNEIRO </name>
<cpf> 00000000000 </cpf>
</registrates>
<registers>
<matricula> 6 </matricula>
<name> ADRIELLE ROSA CAMARGO DE ANDRADE </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 3 </matricula>
<name> GUILHERME QUINTINO RIBEIRO </name>
<cpf> 0000000 </cpf>
</registrates>
<registers>
<matricula> 14 </matricula>
<name> TIAGO DA FONTE LEITE </name>
<cpf> 00000000 </cpf>
</registrates>
<registers>
<matricula> 2 </matricula>
<name> LUIZ ANTONIO SACCO </name>
<cpf> 00000000000 </cpf>
</registrates>
<registers>
<matricula> 10 </matricula>
<name> JULIANA PEREIRA DA CUNHA WALENKAMP </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 8 </matricula>
<name> MARCEL KEITI TOMA </name>
<cpf> 00000000000 </cpf>
</registrates>
<registers>
<matricula> 13 </matricula>
<name> CRISTIANE BONATES MACEDO DE AMO </name>
<cpf> 00000000000 </cpf>
</registrates>
<registers>
<matricula> 11 </matricula>
<name> LUIS ANTONIO PAIN JUNIOR </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 12 </matricula>
<name> FLAVIO DALE LUCHE </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 1 </matricula>
<name> BRUNO VIEIRA ROBERTI </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 4 </matricula>
<name> GUILHERME GAMEIRO DUARTE </name>
<cpf> 00000000 </cpf>
</registrates>
<registers>
<matricula> 7 </matricula>
<name> CARLA FERNANDA PASQUALI </name>
<cpf> 0000000 </cpf>
</registrates>
</list>
</Transaction>
This is my vbs code:
Dim xlApp, xlWkb, SourceFolder, TargetFolder, file
Set xlApp = CreateObject ("excel.application")
Set fs = CreateObject ("Scripting.FileSystemObject")
Const ForWriting = 2`enter code here`
Const TristateTrue = -1
Const xlNormal = 51
SourceFolder = "C: Users Convex Documents MICHAEL XML"
TargetFolder = "C: Users Convex Documents MICHAEL XLS"
xlApp.Visible = false
for each file in fs.GetFolder (SourceFolder) .files
Set xlWkb = xlApp.Workbooks.Open (file)
BaseName = fs.getbasename (file)
FullTargetPath = TargetFolder & "" & BaseName & ".xlsx"
xlWkb.SaveAs FullTargetPath, xlNormal
xlWkb.close
next
'Uncomment this line to delete the source file
'fs.DeleteFile ("C: xml-to-xls xml *. xml")
Set xlWkb = Nothing
Set xlApp = Nothing
Set fs = Nothing
This is the xml:
<? xml version = "1.0" encoding = "utf-8"?>
<Transaction>
<list>
<registers>
<matricula> 5 </matricula>
<name> ANGEL EDUARDO TRIGUEROS CISNEROS </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 9 </matricula>
<name> MARCO AURELIO CARNEIRO </name>
<cpf> 00000000000 </cpf>
</registrates>
<registers>
<matricula> 6 </matricula>
<name> ADRIELLE ROSA CAMARGO DE ANDRADE </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 3 </matricula>
<name> GUILHERME QUINTINO RIBEIRO </name>
<cpf> 0000000 </cpf>
</registrates>
<registers>
<matricula> 14 </matricula>
<name> TIAGO DA FONTE LEITE </name>
<cpf> 00000000 </cpf>
</registrates>
<registers>
<matricula> 2 </matricula>
<name> LUIZ ANTONIO SACCO </name>
<cpf> 00000000000 </cpf>
</registrates>
<registers>
<matricula> 10 </matricula>
<name> JULIANA PEREIRA DA CUNHA WALENKAMP </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 8 </matricula>
<name> MARCEL KEITI TOMA </name>
<cpf> 00000000000 </cpf>
</registrates>
<registers>
<matricula> 13 </matricula>
<name> CRISTIANE BONATES MACEDO DE AMO </name>
<cpf> 00000000000 </cpf>
</registrates>
<registers>
<matricula> 11 </matricula>
<name> LUIS ANTONIO PAIN JUNIOR </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 12 </matricula>
<name> FLAVIO DALE LUCHE </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 1 </matricula>
<name> BRUNO VIEIRA ROBERTI </name>
<cpf> 000000000 </cpf>
</registrates>
<registers>
<matricula> 4 </matricula>
<name> GUILHERME GAMEIRO DUARTE </name>
<cpf> 00000000 </cpf>
</registrates>
<registers>
<matricula> 7 </matricula>
<name> CARLA FERNANDA PASQUALI </name>
<cpf> 0000000 </cpf>
</registrates>
</list>
</Transaction>
question from:
https://stackoverflow.com/questions/65852878/convert-xml-to-xlsx-vbscript 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…