Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel spreadsheet generation results in "different file format than extension error" when opening in excel 2007

The spreadsheet still displays, but with the warning message. The problem seems to occur because Excel 2007 is more picky about formats matching their extensions than earlier versions of Excel.

The problem was initially discovered by an ASP.Net program and produces in the Excel error "The file you are trying to open, "Spreadsheet.aspx-18.xls', is in a different format than specified by the file extension. Verify ...". However, when I open the file it displays just fine. I am using Excel 2007. Firefox identifies the file as an Excel 97-2003 worksheet.

Here is an ASP.NET page which generates the problem:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Spreadsheet.aspx.cs" Inherits="Spreadsheet" %> 

The code behind file looks like:

public partial class Spreadsheet : System.Web.UI.Page {     protected void Page_Load(object sender, EventArgs e)     {         Response.ContentType = "application/vnd.ms-excel";         Response.Clear();         Response.Write("Field\tValue\tCount\n");          Response.Write("Coin\tPenny\t443\n");         Response.Write("Coin\tNickel\t99\n");       }  

}

T

like image 542
Jeff Bloom Avatar asked Mar 16 '09 22:03

Jeff Bloom


People also ask

How do I fix Excel extension errors?

Step 1: Launch Microsoft Excel on your PC. Step 2: Head to the “files” section, and click “Export.” Step 3: In the section, select “change file type” and click on the file with the error. Step 4: Change the file extension and save the file.

How do you fix Excel Cannot open the file Xlsx because the file format or file extension is not valid on Mac?

You can restore the Excel file format, or the file extension is not valid from previous versions. Select the damaged file. Right-click it and click "Properties" > "Previous Version". A list of previous versions will appear; you need to select the option you are interested in and click "Restore" to recover.


1 Answers

http://blogs.msdn.com/vsofficedeveloper/pages/Excel-2007-Extension-Warning.aspx

That is a link basically describing that MS knows about the problem your describe and that it cannot be suppressed from within ASP.NET code. It must be suppressed/fixed on the client's registry.

like image 124
Eric H Avatar answered Sep 19 '22 15:09

Eric H