ASP NET generated excel file has different format than extension

0 votes

I have an outdated Asp.net 2.0 web application. I need to create an excel file with a specified table format (the best way if I can load the template and only put data in code behind). I'm trying to utilize this library to accomplish this. CarlosAg.ExcelXmlWriter: 

http://www.carlosag.net/tools/excelxmlwriter/sample

The final file is generated flawlessly, but when I try to access it in MS Excel, a warning window with the message that the file's format is different from the extension appears (xls). I also wonder if I should open it if I don't trust the file's source. The file opened successfully when I selected yes. The same warning—that the file is damaged and cannot be opened—appears on a separate computer running a different version of Excel (no possibility to open). What's remarkable is that I can access that file correctly and without receiving any errors in other office programs, including WPS Office.

    Dim book As Workbook = New Workbook()
    Dim sheet As Worksheet = book.Worksheets.Add("Sample")
    Dim row As WorksheetRow = sheet.Table.Rows.Add()
    row.Cells.Add("Hello World")
    book.Save("D:\Folder\test.xls")
Jan 5 in Others by Kithuzzz
• 28,700 points
41 views

1 answer to this question.

0 votes
You must include the xlsx file extension.

The legacy (closed) binary format of office files is actually the older Xls file type.

But starting with office 2007, Microsoft switched to using the open XML format for ALL of its office documents (well, ok, outlook pst, and MS Access are exceptions). Try renaming the xlsx document as a zip file if you have any office documents (word, power-point, excel, etc.). You discover that you may now open the zip archive and see, examine, and even edit the XML contained therein.

Therefore, more recent office file formats are actually XML markups, and you can edit them!

In any case, the library you're using unquestionably takes use of the fact that office files are now XML-formatted rather than being stored in a proprietary Microsoft binary format. As a result, these files can now be modified on ANY computer that can handle zip files and text files.

As a result, Excel is alerted to the fact that you are naming the document with a legacy binary file extension (Xls) while opening a plain text XML file. Therefore, you must add the open office XML format extension to that document (xlsx).
answered Jan 5 by narikkadan
• 53,160 points

Related Questions In Others

0 votes
1 answer

Excel cannot open the file because the file format or file extension is not valid - PHP Maatwebsite

Try this: if (ob_get_length() == 0 ) { ...READ MORE

answered Dec 19, 2022 in Others by narikkadan
• 53,160 points
115 views
0 votes
1 answer

Blazor - ClosedXml - excel cannot open the file beacause the file format or extension is not valid

Changed the following code: function BlazorDownloadFile(filename, bytesBase64) { var ...READ MORE

answered Jan 20 in Others by narikkadan
• 53,160 points
59 views
0 votes
1 answer

How to create and download excel document using asp.net

First, download the Open XML Format SDK 2.0. It comes ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 53,160 points
534 views
0 votes
1 answer

How can I convert excel to PDF by Libreoffice and keep all format from excel file?

"Times New Roman" typeface does not have ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 53,160 points
465 views
0 votes
1 answer

'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine

In order to fix this problem, you ...READ MORE

answered Feb 10, 2022 in Others by Soham
• 9,700 points
801 views
0 votes
1 answer

Deleting duplicate rows in Excel using Epplus

You need to re-think this… the while ...READ MORE

answered Feb 23, 2022 in Database by gaurav
• 22,940 points
427 views
0 votes
1 answer

Export DataTable to Excel File

Add Interop References. First we need to ...READ MORE

answered Jun 9, 2022 in JQuery by gaurav
• 22,940 points
217 views
0 votes
1 answer

Program that works in all version of excel

Knowing that all of your users will ...READ MORE

answered Sep 24, 2022 in Others by narikkadan
• 53,160 points
101 views
0 votes
1 answer

How to download SQL data in excel format using asp.net

Solution Download Open XML Download Close XML Library. import this Namespaces using System.IO; using System.Data; using ...READ MORE

answered Nov 14, 2022 in Others by narikkadan
• 53,160 points
156 views
0 votes
1 answer

Prompt message if Excel column has some value in asp.net c#

I believe it is wise to use ...READ MORE

answered Nov 24, 2022 in Others by narikkadan
• 53,160 points
109 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP