最近、Visual Studio 2005 から Visual Studio 2010でコードを書き始めました。データグリッドからExcelにエクスポートするコードが必要です。Visual Studio 2005 では、次のコードが使用されていました。
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=dgd.xls");
Response.Charset = "";
Response.ContentType = "application/vnd.xls";
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
dgd.Visible = true;
dgd.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
これは、Visual Studio 2005 では同じ結果にはなりません。ヘッダーは列に揃えられていません。データグリッド内の画像が Excel で取得されず、データグリッド内のリンクが正しく表示されません。より良いコードは何でしょうか?