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
| try
{
string[] st = new string[lvListeTypes.Columns.Count];
System.IO.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 < lvListeTypes.Columns.Count; col++)
{
sw.Write("\t" + lvListeTypes.Columns[col].Text.ToString());
}
int rowIndex = 0;
int row = 0;
string st1 = "";
for (row = 0; row < lvListeTypes.Items.Count; row++)
{
st1 = "\n";
if (rowIndex <= lvListeTypes.Items.Count)
{
rowIndex++;
for (int col = 0; col < lvListeTypes.Columns.Count; col++)
{
st1 = st1 + "\t" + lvListeTypes.Items[row].SubItems[col].Text.ToString();
}
sw.Write(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);
}
catch (Exception ex)
{
} |
Partager