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
|
DataTable dt = new DataTable();
dt = RecupererListe();
context.Response.ClearContent();
context.Response.AddHeader("content-disposition", "attachment;filename=" + nomFichier + ".xls");
context.Response.ContentType = "application / vnd.ms-excel";
context.Response.ContentEncoding = Encoding.Default;
foreach (DataColumn dc in dt.Columns)
{
context.Response.Write(onglet + dc.ColumnName);
onglet = "\t";
}
context.Response.Write("\n");
foreach (DataRow dr in dt.Rows)
{
onglet = string.Empty;
for (int i = 0; i < dt.Columns.Count; i++)
{
context.Response.Write(onglet + (dr[i] == DBNull.Value ? string.Empty : dr[i].ToString()));
onglet = "\t";
}
context.Response.Write("\n");
}
context.Response.End(); |
Partager