dans la colonne maintenant j ai system.data.datarow
re moi
voila toujours mon souci de data.datarow en affichage dans mon tableau excell je sais pas dou ca vient un peu d aide svp j ai essayé les deux lignes la
_______________________________________
xlApp.Sheets(1).range("A2").value =ds.Tables(0).Rows.Item(1).ToString()
_______________________________________
xlApp.Sheets(1).cells(1, 1) = ds.Tables(0).Rows.Item(1).ToString()
a chaque fois affiche system.data.datarow
merci de vôtre aide par avance
Tu ne spécifies pas sur quelle ligne tu bosses sinon
Code : Sélectionner tout - Visualiser dans une fenêtre à part xlApp.Sheets(1).cells(1, 1) = ds.Tables(0).Rows(0).Item(1).ToString()
un grand merci a ta patience enfin cela fonctionne jevois un fournisseur premiere etape dasn mon tour de vb.net mdr
j aimerais bien pouvoir les faire ajouter la table peu etre une fonction pour ?
Pour exporter tout une DataTable dans une feuille Excel?
Ceci exporte suivant une requete passée en argument. Il ya surement mieux
Code : 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 public void Export_DataGrid(string strCmd) { OleDbConnection oConn; OleDbCommand oCmd; object oMissing= System.Reflection.Missing.Value; Excel.Application appXls = new Excel.ApplicationClass(); appXls.Visible = false; Excel._Workbook Classeur = appXls.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet); Excel._Worksheet Feuille = (Excel._Worksheet) Classeur.ActiveSheet; oConn=new System.Data.OleDb.OleDbConnection(); oConn.ConnectionString=MainFrame.strConn; oCmd=new System.Data.OleDb.OleDbCommand(); oCmd.Connection=oConn; oCmd.CommandText=strCmd; oConn.Open(); OleDbDataReader dr = oCmd.ExecuteReader(); int nLine=5; while (dr.Read()) { for (int nCol=0; nCol < dr.FieldCount; nCol++) { Content = dr[nCol].ToString(); if (nCol == 3) { Content = Content.Replace("Monsieur", "M"); Content = Content.Replace("Madame", "Mme"); if (Content.Length > 0) Content = Content.Remove(0, 1); } if (nCol == 6) { Content = Content.Substring(0, Content.Length-9); } if (Content != "") Feuille.Cells[nLine, nCol+1] = Content; } nLine++; } } oConn.Close(); Feuille.Columns.AutoFit(); appXls.Visible = true; }
te remerci vais decortiquer ton code et je reviens te dire![]()
En gros, lecture ligne par ligne.
On fait une boucle sur les colonnes et on met dans la feuille excel.
Partager