gridview导出数据到excel后显示列和行

发布于 2024-12-23 06:25:16 字数 588 浏览 2 评论 0原文

大家好,我正在执行一项任务,将 gridview 数据导出到 Excel,这是我使用可用的论坛和文章完成的。

但我想在数据导入到excel后显示完整的excel列,这意味着期望网格内容占据的位置我想按原样显示excel的其余列。

我们常见的导出正常方式示例如下

在此处输入图像描述

我的要求是显示如下

< img src="https://i.sstatic.net/cIROq.jpg" alt="在此处输入图像描述">

我按照此处操作

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

Hi all i am having a task to export gridview data to excel which i have done using the forums and articles available.

But i would like to display complete excel columns after the data was imported to excel, means expect the place occupied by the grid content i would like to display the remaining columns of the excel as it is.

Sample the normal way of exporting the we do in common is as follows

enter image description here

My requirement is to show as follows

enter image description here

I followed as per here

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事和酒 2024-12-30 06:25:17

查看你导出的代码你已经去掉了代码中生成的excel的边框。

See your code to export you have removed the border of the excel generated in the code.

森林散布 2024-12-30 06:25:17

您可以使用以下代码来做到这一点

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();

}
-->Return only hearder,not view data.Help Me !
Thank you !
Email:[email protected]

You can use the following code to do it

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();

}
-->Return only hearder,not view data.Help Me !
Thank you !
Email:[email protected]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文