0
我使用下面的代碼來保存數據集到excel和一切工作正常,數據存儲在Excel中,但是當我郵寄Excel的另一端得到的Excel沒有任何數據(條目)。DataSet到excel問題
HttpResponse response = HttpContext.Current.Response;
// first let's clean up the response.object
response.Clear();
response.Charset = "";
Response.ContentEncoding = System.Text.Encoding.Default;
using (StringWriter sw = new StringWriter())
{
using (HtmlTextWriter htw = new HtmlTextWriter(sw))
{
DataGrid dg = new DataGrid();
dg.DataSource = DS.Tables[0];
dg.DataBind();
dg.RenderControl(htw);
string sPath = @"E:\CR-12\Test.xls";
File.WriteAllText(sPath, sw.ToString());
}
}
爲什麼會認爲這個文件是Excel文件而不是HTML? – 2011-04-28 09:08:33
你可以顯示你的代碼,附加Excel文件併發送郵件嗎? – hallie 2011-04-28 09:13:19