IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Création d'un fichier XML Excel.Sheet (Excel)


Sujet :

Scripts/Batch

  1. #1
    Membre actif
    Avatar de troxsa
    Inscrit en
    Novembre 2004
    Messages
    386
    Détails du profil
    Informations personnelles :
    Âge : 50

    Informations forums :
    Inscription : Novembre 2004
    Messages : 386
    Points : 264
    Points
    264
    Par défaut Création d'un fichier XML Excel.Sheet (Excel)
    Bonjour,

    Je cherche sur le net mais je n'ai pas trouvé comment faire

    Je cherche a écrire le début d'un fichier XML de type Office Excel

    Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    <?xml version="1.0"?>
    <?mso-application progid="Excel.Sheet"?>
    <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
     xmlns:o="urn:schemas-microsoft-com:office:office"
     xmlns:x="urn:schemas-microsoft-com:office:excel"
     xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
     xmlns:html="http://www.w3.org/TR/REC-html40">
     <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
      <Author>XXXXXXXXX</Author>
      <LastAuthor>XXXXXXXXX</LastAuthor>
      <Created>xxxx-xx-xxTxx:xx:xxZ</Created>
      <Company>XXXXXXXXX</Company>
      <Version>14.00</Version>
     </DocumentProperties>
     <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
      <AllowPNG/>
     </OfficeDocumentSettings>
     <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
      <WindowHeight>11820</WindowHeight>
      <WindowWidth>28515</WindowWidth>
      <WindowTopX>120</WindowTopX>
      <WindowTopY>45</WindowTopY>
      <ProtectStructure>False</ProtectStructure>
      <ProtectWindows>False</ProtectWindows>
     </ExcelWorkbook>
     <Styles>
      <Style ss:ID="Default" ss:Name="Normal">
       <Alignment ss:Vertical="Bottom"/>
       <Borders/>
       <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
       <Interior/>
       <NumberFormat/>
       <Protection/>
      </Style>
     </Styles>

    Je pourrais le faire avec un simple Set-Content mais j'aimerais utiliser les objets XML directement
    Pour l'instant j'ai pas grand chose et je bloque déjà sur le comment écrire la ligne <?mso-application progid="Excel.Sheet"?>.

    Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    $doc = new-object xml
    $decl = $doc.CreateXmlDeclaration("1.0", "UTF-8", $null)
    $rootNode = $doc.CreateElement("Workbook");
    $doc.InsertBefore($decl, $doc.DocumentElement)
    $doc.AppendChild($rootNode);
    $doc.Save("..........\testwrite.xml")

    En vous remerciant d'avance

  2. #2
    Membre actif
    Avatar de troxsa
    Inscrit en
    Novembre 2004
    Messages
    386
    Détails du profil
    Informations personnelles :
    Âge : 50

    Informations forums :
    Inscription : Novembre 2004
    Messages : 386
    Points : 264
    Points
    264
    Par défaut
    Peut être pas super comme code et c'est pas du tout comme je voulais (en XML Object) mais ça fonctionne et c'est déjà pas mal
    Je poste le code au cas ou ...


    Code PowerShell : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    Function ConvertArrayToXMLExcel($DataConvert, $NameXML)
    {
        $sb = New-Object -TypeName "System.Text.StringBuilder"
        $sb.Append('<?xml version="1.0" encoding="UTF-8"?>')
        $sb.Append('<?mso-application progid="Excel.Sheet"?>')
     
     
        $sb.Append('<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"'+"`r`n")
        $sb.Append('xmlns:o="urn:schemas-microsoft-com:office:office"'+"`r`n")
        $sb.Append('xmlns:x="urn:schemas-microsoft-com:office:excel"'+"`r`n")
        $sb.Append('xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"'+"`r`n")
        $sb.Append('xmlns:html="http://www.w3.org/TR/REC-html40">'+"`r`n")
     
     
        $headers = $DataConvert | Get-member -MemberType 'NoteProperty' | Select-Object -ExpandProperty 'Name'
     
     
        $sb.Append('<Worksheet ss:Name="out_Resultat_Tasks">'+"`r`n")
        $sb.Append('<Table>'+"`r`n")
        #$sb.Append('<Column ss:Index="1" ss:AutoFitWidth="0" ss:Width="230"/>'+"`r`n")
        #$sb.Append('<Column ss:Index="2" ss:AutoFitWidth="0" ss:Width="80"/>'+"`r`n")
        #$sb.Append('<Column ss:Index="3" ss:AutoFitWidth="0" ss:Width="100"/>'+"`r`n")
        $sb.Append('<Row>'+"`r`n")
     
     
        foreach($item in $headers)
        {
            $sb.Append('<Cell><Data ss:Type="String">' + $item + "</Data></Cell>`r`n")
        }
     
     
        $sb.Append('</Row>')
     
     
        foreach($itemDB in $DataConvert)
        {
            $sb.Append('<Row>')
     
     
            foreach($itemHeader in $headers)
            {
                $sb.Append('<Cell><Data ss:Type="String">' + $itemDB.$itemHeader + "</Data></Cell>`r`n")
            }  
            $sb.Append('</Row>')
        }
        $sb.Append('</Table></Worksheet>')
        $sb.Append('</Workbook>')
        $sb.ToString() | Out-File .\$NameXML
     
     
    }
     
     
    $db = Import-Csv -Path "........\test.csv" -Encoding Default
    ConvertArrayToXMLExcel -DataConvert $db -NameXML .\Test.xml

    J'ai pris StringBuilder car les données peuvent être de gros traille ..
    Si vous avez des idées pour faire des optimisations, je prends

Discussions similaires

  1. [XSD] Création d'un fichier XML
    Par Taylor² dans le forum Format d'échange (XML, JSON...)
    Réponses: 1
    Dernier message: 06/06/2006, 22h16
  2. Réponses: 1
    Dernier message: 20/10/2005, 10h32
  3. Création d'un fichier XML
    Par fantasio31 dans le forum Général Python
    Réponses: 2
    Dernier message: 09/09/2004, 17h06
  4. [XML] Création d'un fichier XML
    Par TheDarkLewis dans le forum Langage
    Réponses: 6
    Dernier message: 24/07/2004, 18h27
  5. ligne d'entête création d'un fichier XML
    Par cduterme dans le forum XML/XSL et SOAP
    Réponses: 6
    Dernier message: 23/02/2004, 15h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo