Cosetta stupida...classe che emette una tabella compatibile con Excel da un DataSet (Italiano (Italian))

Cosetta stupida...classe che emette una tabella compatibile con Excel da un DataSet

Friday, 26 March 2004

//

Less than a minute

Molto semplice e basato sulla uno di cui ho fatto il blog in precedenza (beh non in base al codice ma in base alla stessa idea). In ogni caso, collegare questo fino a un pulsante di collegamento, passare in un set di dati e fornirà un file compatibile Excel scaricabile ...

classe pubblica GetExcel

{

vuoto statico pubblico Convert(DataSet ds, int dataTableId, HttpResponse response, string fileName)

{

DataGrid dg = nuova DataGrid();

dg.DataSource = ds.Tables[dataTableId];

dg.DataBind();

response.Buffer = true;

response.ContentType="application/vnd.ms-excel";

AddHeader("Content-Disposition," "attachment;filename=" + fileName) ;

usando(StringWriter sw = new StringWriter())

{

usando(HtmlTextWriter = nuovo HtmlTextWriter(sw)))

{

dg.RenderControl(scrittore);

risposta.Scrivi(sw.ToString());

}

}

risposta.Fine();

}

vuoto statico pubblico Convert(DataSet ds, int dataTableId, HttpResponse response)

{

Convert(ds,dataTableId,response,"report.xls");

}

vuoto statico pubblico Convert(DataSet ds, risposta HttpResponse)

{

Convert(ds,0,response);

}

}

Finding related posts...
logo

© 2026 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.