1. データテーブルのデータコレクションをインポートします
2. エクスポート機能
/// <summary>
/// Web エクスポートの場合
/// </summary>
/// <param name="dtSource">ソース DataTable</param>
/// <param name="strHeaderText">ヘッダー テキスト< /param>
/// <param name="strFileName">ファイル名</param>
public static void ExportByWeb(DataTable dtSource, string strHeaderText, string strFileName)
{
HttpContext curContext = HttpContext.Current;
// 設置コードおよび付属品格式
curContext.Response.ContentType = "application/vnd.ms-excel";
curContext.Response.ContentEncoding = エンコーディング.UTF8;
curContext.Response.Charset = "";
curContext.Response.AppendHeader("Content-Disposition",
"attachment;filename=" + HttpUtility.UrlEncode(strFileName, Encoding.UTF8));
curContext.Response.BinaryWrite(Export(dtSource, strHeaderText).GetBuffer());
curContext.Response.End();
}
3. 電話をかける
dt はエクスポートする必要があるデータセットです
ExportByWeb(dt, "excel エクスポート", "report.xls");