Asp.net在2007年从GridView导出到Excel [英] Asp.net Export to Excel from GridView in 2007

查看:84
本文介绍了Asp.net在2007年从GridView导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在asp.net中导出到excel时获得



你用的文件试图打开的格式与文件扩展名指定的格式不同



Hi,

Iam getting when export to excel in asp.net

The file you are trying to open is in a different format than specified by the file extension

Response.ClearContent();
            Response.ContentType = "application/octet-stream";
            Response.AddHeader("Content-Disposition", "attachment; filename=Test.xls");

            GridView excel = new GridView();
            excel.DataSource = dt;
            excel.DataBind();
            excel.RenderControl(new HtmlTextWriter(Response.Output));

            Response.Flush();
            Response.End();





谢谢,

Krishna



Thanks,
Krishna

推荐答案

按照以下步骤操作:



1)启动注册表编辑器。(运行regedit.exe)



2)如果系统提示您输入管理员密码或进行确认,请输入密码,或单击继续。



3)找到并单击以下注册表子项:



HKEY_CURRENT_USER \ Software /\\ Microsoft \ Office \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ >



4)在编辑菜单上,指向新建,然后单击DWORD值。



5)键入ExtensionHardening,然后按ENTER键。



6)右键单击ExtensionHardening,然后单击修改。



7)在数值数据框中,输入0,然后单击确定。



您已完成。



:doh: [另一种解决方法]:



ClosedXML - OpenXML的简便方法 [ ^ ]



[更新]:



Excel 2007扩展警告开幕来自网站的Excel工作簿 [ ^ ]





问候......:笑:
Follow below steps:

1) Start Registry Editor.(run regedit.exe)

2) If you are prompted for an administrator password or for a confirmation, type the password, or click Continue.

3) Locate and then click the following registry subkey:

HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Excel\Security

4) On the Edit menu, point to New, and then click DWORD Value.

5) Type ExtensionHardening, and then press ENTER.

6) Right-click ExtensionHardening, and then click Modify.

7) In the Value data box, type 0, and then click OK.

You are done.

:doh:[Another workaround]:

ClosedXML - The easy way to OpenXML[^]

[Update]:

Excel 2007 Extension Warning On Opening Excel Workbook from a Web Site[^]


Regards.. :laugh:


ds = //fill your dataset ds
        DataTable dt = new DataTable();
        dt = ds.Tables[0];
        string attachment = "attachment; filename=//givefilename";
        Response.ClearContent();
        Response.AddHeader("content-disposition", attachment);
        Response.ContentType = "application/vnd.ms-excel";
        string tab = "";
        foreach (DataColumn dc in dt.Columns)
        {
            Response.Write(tab + dc.ColumnName);
            tab = "\t";
        }
        Response.Write("\n");
        int i;
        foreach (DataRow dr in dt.Rows)
        {
            tab = "";
            for (i = 0; i < dt.Columns.Count; i++)
            {
                Response.Write(tab + dr[i].ToString());
                tab = "\t";
            }
            Response.Write("\n");
        }
        Response.End();


这篇关于Asp.net在2007年从GridView导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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