Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
110 views
in Technique[技术] by (71.8m points)

adsutil.vbs - Convert xml to xlsx vbscript

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...