Help with Aspose Excel 2010

First let me say that the site’s search engine is terrible. The navigation on your web site is quite bad.


That said, the product is working great serving XLS files (Excel97 / 2003) to Windows XP users who have Excel 2003 locally.

If I hit the server from a Windows 7 machine that has Excel 2010 on it, I get "Excel cannot open the file because the file format or file extension is invalid. File may be corrupted, etc."

No big deal, let me try it with a few changes:

e.ContentType = “application/vnd.ms-excel”;
e.ContentFileName = “ELTFile.Output.xls”;
private FileFormatType _excelFileFormat = FileFormatType.Excel97To2003;
to

e.ContentType = “application/vnd.openxml”;
e.ContentFileName = “ELTFile.Output.xlsx”;
private FileFormatType _excelFileFormat = FileFormatType.Xlsx;
I also tried application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, instead of “openxml”.

What it says on my Windows 7 machine is the same thing "Excel cannot open the file …"

So obviously, there’s more to converting my code to Excel 2010 than I know of. What am I missing?
Hi,

jj30:
First let me say that the site's search engine is terrible. The navigation on your web site is quite bad.

Please elaborate where you did find the issue. Our Site admins will look into it to fix it soon.

jj30:
That said, the product is working great serving XLS files (Excel97 / 2003) to Windows XP users who have Excel 2003 locally.

If I hit the server from a Windows 7 machine that has Excel 2010 on it, I get "Excel cannot open the file because the file format or file extension is invalid. File may be corrupted, etc."
.............
So obviously, there's more to converting my code to Excel 2010 than I know of. What am I missing?

Please see a sample cod below on how response the Excel workbook on the client side.
//........
//Your code goes here.
//.............

/*Send workbook to response*/
OoxmlSaveOptions xSaveOptions = new OoxmlSaveOptions(SaveFormat.Xlsx);
MemoryStream tempStream = new MemoryStream();
_workbook.Save(tempStream, xSaveOptions);
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + "MyFile.xlsx");
Response.Flush();
Response.BinaryWrite(tempStream.ToArray());
Response.End();

Also, you may simply use relevant Workbook.Save() overload and do it in one line, see the document:
http://www.aspose.com/docs/display/cellsnet/Saving+Files

I will paste the simplest sample code here:
//Creating an Workbook object
Workbook workbook = new Workbook(FileFormatType.Xlsx);
//... Your code goes here

//Save in xlsx format and send the file to user so that he may open the file in
//some application or save it to some location
workbook.Save(this.Response, "Report.xlsx", ContentDisposition.Attachment, new OoxmlSaveOptions());
Response.End();

Yes, I did those three changes already.


1) Change to mime type
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
2) Changed file name extension from XLS to XLSX
3) Changed the FileFormatType to FileFormatType.XLSX

(We are letting the browser handle it so that ‘open’, ‘save’ and ‘cancel’ are the only options, so the other changes you listed don’t apply to the code we have.)

I just redid them to confirm my error message: "Excel cannot open the file because the file format or file extension is not valid. Verify the file has not been corrupted and that the file extension matches the type of file."

So I checked the extension mappings in Windows 7, and remapped them to ensure that it was pointed to the Office 2010 Excel… same thing.

Can you give me more help beyond what you’ve already given me? Thank you.

(I don’t know if this will help, but it does the same thing if I pick ‘Save’ in the dialog and try to open it later.)

Hi,

It works fine here in Web Application / ASP.NET projects. I don’t think your issue has any links to Aspose.Cells for .NET product. I think you may google to find out more information about your issue, e.g see the online resources for help:

http://www.coderanch.com/t/582495/open-source/opening-xlsx-file-when-downloaded

http://answers.microsoft.com/en-us/office/forum/office_2010-customize/excel-cannot-open-the-file-asdxlsx-because-the/130ea13c-55ca-4149-8526-c03a39380a0c

Also, please don’t involve Aspose.Cells product / APIs to confirm the issue. You may simply open an Excel file and save to Response object, you should get the same error.

e.g

FileStream fs1 = new FileStream("d:\\Book1.xlsx", FileMode.Open, FileAccess.Read);

byte[] data1 = new byte[fs1.Length];

fs1.Read(data1, 0, data1.Length);

this.Response.ContentType = "application/xlsx";

Response.AddHeader( "content-disposition","inline; filename=outBook1.xlsx");

Response.BinaryWrite(data1);

Response.End(); 

We also recommend you to kindly try our latest version:
Aspose.Cells for .NET (Latest Version)

Also, if you still think it is an issue with our product, please create a sample application and use the relevant Workbook.Save() overloaded method, zip the project and post it here, we will check it soon.

Thank you.

Save Editcancel

Hi Amjad,


Yes, I think you’re right: It has nothing to do with Aspose.

As an example of how the web site may be improved, I tried to find my post through the web site and gave up after a few minutes.

An example of something you’ve done right: The RSS link allowed me to see your response in my Outlook, and find it without having to use your site’s search.

It’s Friday at 4:30 p.m. … I will confirm that it has nothing to do with Aspose, using the code you sent me, ASAP. Thanks.

Hi,

Please use the following link to search for all the posts, you have made to forums.

http://www.aspose.com/community/search/search-results.aspx?u=176292&o=DateDescending

In case, if you lose this link, then you can find it by clicking on you id and it will take you to the following page.

http://www.aspose.com/community/members/jj30.aspx

From there, you can click on your posts to search your previous posts.

Also you can directly go there by clicking the Posts link under your id.

I have identified the navigation issue as a pet peeve. When I am looking at my discussion thread and wish to reply to something, I must sign in. No big deal, I sign in. But when I do, it does not redirect me back to the discussion thread. Instead I am at some generic splash page, and must go back and find the link.


I tried the code to confirm it’s not an aspose issue.

FileStream fs1 = new FileStream(“Book1.xlsx”, FileMode.Open, FileAccess.Read);
byte[] data1 = new byte[fs1.Length];
fs1.Read(data1, 0, data1.Length);
this.Response.ContentType = “application/xlsx”;
Response.AddHeader(“content-disposition”, “inline; filename=outBook1.xlsx”);
Response.BinaryWrite(data1);
Response.End();

Unfortunately, it worked. This means that it’s not a configuration issue with Windows 7.

The other code you’ve given me, I can’t use, because with the object orientation, I can’t find where to apply it. (And the only difference btw yours and mine is the OoxmlSaveOptions).

Here is the intro to my predecessor’s object:


public class ExcelExport
{
///
/// Licence load for the Aspose.Cells Component
///
private Aspose.Cells.License _cellsLicence;
///
/// Working Workbook.
///
private Workbook _workbook;
///
/// Excel file format
///
private FileFormatType _excelFileFormat = FileFormatType.Xlsx;////JJJJJJJ
///
private List _eltExportDDLists;

///
/// Default Constructor
///
public ExcelExport()
{
this._cellsLicence = new Aspose.Cells.License();
this._cellsLicence.SetLicense(“Aspose.Cells.lic”);
}


So, I think I have spent enough time on this issue. I think that it’s probably best if I just use XLS and let the backwards-compatibility handle it. My only issue then would be if the user ‘saves as’ an XLSX (2010 format) and then tries to import it. What the code would do at that point.

Hi,

Please create a simple project using latest version v7.3.2 with its Aspose.Cells API, zip it and post it here to reproduce the issue on our end as we could not reproduce the issue on our end.

By the way, did you try this simplest code in a simple ASP.NET web application, The code is equal to the above code using Aspose.Cells APIs, e.g

FileStream fs1 = new FileStream(“Book1.xlsx”, FileMode.Open, FileAccess.Read);

Workbook workbook = new Workbook(fs1);

workbook.Save(HttpContext.Current.Response, “outFile.xlsx”, ContentDisposition.Inline, new OoxmlSaveOptions(SaveFormat.Xlsx));