0

我有一个 vbscript 代码,我在其中将 xml 转换为 xlsx。但是,在转换时会重复信息并采用列的顺序。如何反转或调整?因为我无法正确格式化。如果您使用excel并手动打开并转换为xlsx,则它是正确的。

这是我的vbs代码:

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

这是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>
4

0 回答 0