你如何生成ASP.NET Excel 2007文件没有得到警告信息吗? [英] How do you generate an Excel 2007 file in ASP.NET without getting a warning message?

查看:107
本文介绍了你如何生成ASP.NET Excel 2007文件没有得到警告信息吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我打开我我的ASP.NET页面上生成与Excel 2007中xls文件,我得到以下错误:

Whenever I open an xls file I generated on my ASP.NET page with Excel 2007, I get the following error:

您试图打开,'filename.xls'文件,是在一个不同的格式不是由文件扩展名指定。验证该文件没有损坏,是来自可信来源打开文件之前。要现在打开文件?

The file you are trying to open, 'filename.xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?

如果我点击是,一切看起来很好,但它很烦人给我们的客户有通过它每一次点击。如果他们使用2003,没问题,但在2007年它给这个错误。这里的code我使用:

If I click 'Yes', everything looks fine, but it's annoying to our customers to have to click through it each time. If they use 2003, no problem, but on 2007 it gives this error. Here's the code I use:

string style = @"<style> .text { mso-number-format: \@ } </style> ";

Response.Clear();
Response.AddHeader("content-disposition", string.Format("attachment;filename=OperationsReport_Rejects_{0}.xls", DateTime.Today.ToString("yyyyMMdd")));
Response.Charset = "";
Response.ContentType = "application/vnd.xls";

StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

reportOperationsRejectsGridView.RenderControl(htmlWrite);
Response.Write(style);
Response.Write(stringWrite.ToString());
Response.End();

有谁知道是什么原因造成它来表现不同的2003年和2007年?

Does anyone know what is causing it to behave differently on 2003 and 2007?

推荐答案

的Office 2007使用基于XML的文件格式是从previous二进制文件格式不同。

Office 2007 uses XML based file formats that are different from the previous binary file formats.

什么Excel 2007中保存不是的.xls 文件,但一个的.xlsx 文件。

What Excel 2007 saves is not an .xls file, but an .xlsx file.

你所创建实际上既不。这是一个Excel文件的HTML出口。有些版本将导入前无缝导入HTML作为一个Excel文档,有些版本会提醒你,它实际上不是一个Excel文档。

What you are creating is actually neither. It's an HTML export of an excel file. Some versions will seamlessly import the HTML as an excel document, some versions will warn you that it's actually not an Excel document, before importing it.

如果您创建一个实际的的.xls 文件时,Excel 2007会在兼容模式下打开它,从无怨言。

If you create an actual .xls file, Excel 2007 will open it in compatibility mode without complaining.

这篇关于你如何生成ASP.NET Excel 2007文件没有得到警告信息吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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