数据集转excel问题
我使用下面的代码将数据集保存到Excel,一切正常,数据存储在Excel中,但是当我邮寄Excel时,另一端得到的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());
}
}
I am Using the below code to save a dataset to excel and everything is working fine and the data is stored in the excel , but when i mail the excel the excel got on the other end is without any data (entries) in it.
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());
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于此有很多问题。尝试 https://stackoverflow.com/questions/2041417/export-to-excel-in-c对于初学者来说
There's quite a lot of questions tagged about this. Try https://stackoverflow.com/questions/2041417/export-to-excel-in-c for starters