【问题标题】:DataSet to excel issue数据集到excel问题
【发布时间】:2011-04-28 08:56:57
【问题描述】:

我正在使用下面的代码将数据集保存到 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());
            }       
        }

【问题讨论】:

  • 为什么会认为这个文件是 Excel 文件而不是 HTML?
  • 你能展示你的代码,附加excel文件并发送邮件吗?

标签: c# asp.net datagrid export-to-excel


【解决方案1】:

有很多关于这个的问题。尝试https://stackoverflow.com/questions/2041417/export-to-excel-in-c作为初学者

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-24
    • 2011-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多