|
|
|
|
Bonjour,
voila ma question est simple, du moins je crois,
j'utilise visual studios 2008 et j'ai besoin de faire un log dans un fichier excel et je me demande comment faire pour ecrire dans un fichier excel avec c#
je n'ai pas besoin de faire de graphique ou de macro, rien de complexe juste ecrire dans les cellules
sa fait 2 semaine que je chercher sur internet et j'ai toujours rien trouver
merci de votre aide
bonne journee/ soiree
Configuration: Windows Vista Opera 9.52 Visual Studios 2008
Tu écrit de façon séquentielle dans un fichier texte dont tu met comme extension .csv
"4";"2";"y";;"2";"10"; "5";"2";"y";;"2";"10"; "6";"2";"n";"IRIDIA";"3";"80"; "7";"4";"y";;"1";"1"; "2";"6";"y";;"1";"100"; "3";"28";"y";;"1";"100"; "11";"57";"y";;"1";"100"; "8";"110";"y";;"1";"50"; "9";"110";"y";;"3";"50"; "1";"121";"y";;"1";"100"; Tu l'aura deviné, chaque ligne représente une ligne sur excel, et chaque valeur une cellule. Pour faire des sauts de lignes tu écris ceci dans ton fichier .csv à partir de ton programme en C# : \n Si tu as besoin d'aide sur la façon de manipuler des fichiers séquentiels n'hésite pas, sinon voici la piste : StreamWriter. Bonne chance. |
En fait tu as tout intérêt à créer ton fichier Excel en XML.
Colonne 1 | Colonne 2 | Colonne 3 Nom 1 | Prenom 1 | Age 1 Nom 2 | Prenom 2 | Age 2 Tu peux grâce à celà mettre de style dans ta feuille (ici les titres des colonnes en gras), ou alors faire plusieurs "Workbook" comme tu dit :) Du côté d'une library qui te permette de manipuler un fichier Excel directement je n'ai rien trouvé. <?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>Scriptiz</Author> <LastAuthor>Scriptiz</LastAuthor> <Created>2009-01-05T17:14:29Z</Created> <Version>12.00</Version> </DocumentProperties> <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <WindowHeight>8520</WindowHeight> <WindowWidth>18720</WindowWidth> <WindowTopX>240</WindowTopX> <WindowTopY>105</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> <Style ss:ID="s62"> <Font ss:FontName="Calibri" x:Family="Swiss" ss:Size="11" ss:Color="#000000" ss:Bold="1"/> </Style> </Styles> <Worksheet ss:Name="Feuil1"> <Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="3" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15"> <Row> <Cell ss:StyleID="s62"><Data ss:Type="String">Colonne 1</Data></Cell> <Cell ss:StyleID="s62"><Data ss:Type="String">Colonne 2</Data></Cell> <Cell ss:StyleID="s62"><Data ss:Type="String">Colonne 3</Data></Cell> </Row> <Row> <Cell><Data ss:Type="String">Nom 1</Data></Cell> <Cell><Data ss:Type="String">Prenom 1</Data></Cell> <Cell><Data ss:Type="String">Age 1</Data></Cell> </Row> <Row> <Cell><Data ss:Type="String">Nom 2</Data></Cell> <Cell><Data ss:Type="String">Prenom 2</Data></Cell> <Cell><Data ss:Type="String">Age 2</Data></Cell> </Row> </Table> <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <PageSetup> <Header x:Margin="0.3"/> <Footer x:Margin="0.3"/> <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/> </PageSetup> <Print> <ValidPrinterInfo/> <PaperSizeIndex>0</PaperSizeIndex> <HorizontalResolution>600</HorizontalResolution> <VerticalResolution>600</VerticalResolution> </Print> <Selected/> <Panes> <Pane> <Number>3</Number> <ActiveRow>2</ActiveRow> <ActiveCol>2</ActiveCol> </Pane> </Panes> <ProtectObjects>False</ProtectObjects> <ProtectScenarios>False</ProtectScenarios> </WorksheetOptions> </Worksheet> <Worksheet ss:Name="Feuil2"> <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15"> </Table> <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <PageSetup> <Header x:Margin="0.3"/> <Footer x:Margin="0.3"/> <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/> </PageSetup> <ProtectObjects>False</ProtectObjects> <ProtectScenarios>False</ProtectScenarios> </WorksheetOptions> </Worksheet> <Worksheet ss:Name="Feuil3"> <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1" x:FullRows="1" ss:DefaultColumnWidth="60" ss:DefaultRowHeight="15"> </Table> <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <PageSetup> <Header x:Margin="0.3"/> <Footer x:Margin="0.3"/> <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/> </PageSetup> <ProtectObjects>False</ProtectObjects> <ProtectScenarios>False</ProtectScenarios> </WorksheetOptions> </Worksheet> </Workbook> |
Waouh j'ai trouvé un truc super sympa qui va t'aider :
|
Voici tant que j'y suis un petit exemple de manipulation assez complet d'un classeur (ajout de feuille, ...) :
|