【问题标题】:Sql server Procedure Output convert to CSV File in asp.netSql server 过程输出在 asp.net 中转换为 CSV 文件
【发布时间】:2014-07-04 19:40:44
【问题描述】:

请提供一个 dll 或一种将 Sql 存储过程输出(包含近 100 万的巨量记录)转换为 asp.net windows 服务中的 CSV 文件的方法。提前致谢

【问题讨论】:

  • Google 是您的朋友。我们不会为你编写代码

标签: asp.net


【解决方案1】:
protected void btnExportCSV_Click(object sender, EventArgs e)
{
    Response.Clear();
    Response.Buffer = true;
    Response.AddHeader("content-disposition",
     "attachment;filename=GridViewExport.csv");
    Response.Charset = "";
    Response.ContentType = "application/text";

    GridView1.AllowPaging = false;
    GridView1.DataBind();

    StringBuilder sb = new StringBuilder();
    for (int k = 0; k < GridView1.Columns.Count; k++)
    {
        //add separator
        sb.Append(GridView1.Columns[k].HeaderText + ',');
    }
    //append new line
    sb.Append("\r\n");
    for (int i = 0; i < GridView1.Rows.Count; i++)
    {
        for (int k = 0; k < GridView1.Columns.Count; k++)
        {
            //add separator
            sb.Append(GridView1.Rows[i].Cells[k].Text + ',');
        }
        //append new line
        sb.Append("\r\n");
    }
    Response.Output.Write(sb.ToString());
    Response.Flush();
    Response.End();
}

参考上面的代码

请看下面的链接

http://www.aspsnippets.com/Articles/Export-GridView-To-Word-Excel-PDF-CSV-Formats-in-ASP.Net.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-19
    • 2014-11-26
    • 2012-05-19
    相关资源
    最近更新 更多