Gridview到MS Office或Excel [英] Gridview to MS office or Excel

查看:74
本文介绍了Gridview到MS Office或Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生
Gridview to或Excel工作正常.我正在使用代码Mr.Nandakishorerao.它确实工作正常,但在将数据gridview导出为ex​​cel时出现错误,下面我指出了错误.

实际名称:REKHA MEHTA
在excel中给出结果:REKHA&MEBTA

请给我解决方法.
我正在使用以下代码

Dear sir
Gridview to or Excel is working fine. I am using the code Mr.Nandakishorerao. it''s really working fine but there was a mistake when exporting data gridview to excel below i noted the error.

Actual name:REKHA MEHTA
Given result in excel:REKHA MEHTA

Please give me the solution.
I am using following code

private void excelexport()
    {
        Response.Clear(); 
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.csv"); 
        Response.Charset = ""; 
        Response.ContentType = "application/text";
        gridviewsta.AllowPaging = false;
        gridviewsta.DataBind(); 
        StringBuilder sb = new StringBuilder();
        for (int k = 0; k < gridviewsta.Columns.Count; k++) 
        { //add separator 
            sb.Append(gridviewsta.Columns[k].HeaderText + ',');
        } //append new line 
        sb.Append("\r\n");
        for (int i = 0; i < gridviewsta.Rows.Count; i++)
        {
            for (int k = 0; k < gridviewsta.Columns.Count; k++) 
                { //add separator 
                    sb.Append(gridviewsta.Rows[i].Cells[k].Text + ','); } //append new line 
                    sb.Append("\r\n"); 
                } 
        Response.Output.Write(sb.ToString()); 
        Response.Flush(); 
        Response.End();
    }

推荐答案

检查链接[

这篇关于Gridview到MS Office或Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆