aymensmida
Messages postés6Date d'inscriptionvendredi 6 mai 2005StatutMembreDernière intervention26 mars 2011
-
7 mars 2011 à 15:36
aymensmida
Messages postés6Date d'inscriptionvendredi 6 mai 2005StatutMembreDernière intervention26 mars 2011
-
9 mars 2011 à 22:17
Lors de l'export d'un listview vers Excel en utilisant ce code j'ai eu un problème c'est qu'il ya un saut de ligne vide entre chaque ligne du listview exporté et j’aimerais bien éviter ce saut de ligne SVP de m'aider :)
Voici le code:
try
{
string[] st = new string[listView1.Columns.Count];
DirectoryInfo di = new DirectoryInfo(@"c:");
if (di.Exists == false)
di.Create();
StreamWriter sw = new StreamWriter(@"c:\Rapport.xls", false);
sw.AutoFlush = true;
for (int col = 0; col < listView1.Columns.Count; col++)
{
sw.Write("\t" + listView1.Columns[col].Text.ToString());
}
int rowIndex = 0;
int row = 0;
string st1 = "";
for (row = 0; row < listView1.Items.Count; row++)
{
st1 = "\n";
if (rowIndex <= listView1.Items.Count)
{
rowIndex++;
for (int col = 0; col < listView1.Columns.Count; col++)
{
st1 = st1 + "\t" + listView1.Items[row].SubItems[col].Text.ToString();
}
sw.WriteLine(st1);
}
}
sw.Close();
FileInfo fil = new FileInfo(@"c:\Rapport.xls");
if (fil.Exists == true)
{
MessageBox.Show("Exportation Réalisée Avec Succès Vers Excel", "Exportation En Excel", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else
MessageBox.Show("Echec D'Exportation Vers Excel", "Exportation En Excel", MessageBoxButtons.OK, MessageBoxIcon.Error);