Issue opening generated excel-files on Macintosh

Oct 4, 2010 at 9:16 AM

Hello,

Found this project and implemented it since it was perfect for the needs in my project. It works like a charm, or so I thought. While the Excel-files look and behave like they should when opened in Office Excel in a windows environment, there seems to be some issue in regards to opening them on a Macintosh.

I'm using NPOI 1.2.3 for .NET 2.0. The project is using the .NET framework 3.5 and is a ASP.NET webpage where some statistical data can be exported to Excel. Due to user requirements, the files I generate are to be compatible with early Excel-versions (97-2003), which seems to be working fine.

One interesting thing I noted is that when opening the generated file in Excel on a PC environment, with Office Excel 2007 at least, and then saving it without doing any changes, the file can then be opened on the Macintosh without any problem. I therefore tried to compare the generated excel file before and after the re-save; one differance found is the file size, another some header attributes. By setting the attributes Scale & LinksDirty (se code example below) to false when generating the file, the attributes are now the same before and after the re-save but it made no differance sadly - the file can still not be opened on any Macintosh.

I'm kinda at an loss here, what am I missing? Thanks in advance for any help in the matter.

 

Code example... Instancing: 

            HSSFWorkbook _workbook = new HSSFWorkbook();
            NPOI.HPSF.DocumentSummaryInformation dsi = NPOI.HPSF.PropertySetFactory.CreateDocumentSummaryInformation();
            dsi.Scale = false;
            dsi.LinksDirty = false;
            _workbook.DocumentSummaryInformation = dsi;

           HSSFWorkbook _worksheet1 = _workbook.CreateSheet("Statistics");

            _worksheet1.FitToPage = false;
            _worksheet1.PrintSetup.Landscape = true;
            _worksheet1.SetMargin(MarginType.TopMargin, 0.3);
            _worksheet1.SetMargin(MarginType.BottomMargin, 0.3);
            _worksheet1.SetMargin(MarginType.LeftMargin, 0.3);
            _worksheet1.SetMargin(MarginType.RightMargin, 0.3);

 

Once populated with values, the workbook is streamed to the client

        public static void StreamToClient(HSSFWorkbook workbook, string filename)
        {
            // Writing the workbook content to the MemoryStream...
            MemoryStream ms = new MemoryStream();
            workbook.Write(ms);

            // MemoryStream to client
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
            HttpContext.Current.Response.Charset = "iso-8859-1";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("iso-8859-1");
            HttpContext.Current.Response.AddHeader("content-length", Convert.ToString(ms.Length));
            HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
            HttpContext.Current.Response.BinaryWrite(ms.ToArray());
            HttpContext.Current.Response.End();
        }

 

 

Oct 7, 2010 at 1:57 AM

Sorhati,

Can you post a sample file so I can try opening on my MAC.  What version of Office are you using (Office 2008 or Office 2004)?  Do you get any errors when you open the file, if so what are they?

Oct 7, 2010 at 9:51 AM

One customer got 10 Macintoshs, all of which with the same issue - they can open the generated file, but it doesnt contain any data. Unclear weather it displays a blank spreadsheet or no spreadsheet at all. I'm trying to get version info from them but they aren't as forthcoming as one could've hoped for sadly. They did manage to retrive build info to me (10.0.1) but not the actual office version used. However, my bet is Office 2008 since I found some hints on the net in regards to this problem (or similar rather).

Seems like with Office 2008 SR2 there have been confirmed to be some issues opening excel files generated outside Excel, when having been generated in POI mentioned as an example. See the discussion here for instance: https://issues.apache.org/bugzilla/show_bug.cgi?id=47559

The problem was supposedly due to uncertainity about open xml standard used, so should only occur with .xlsx files, and has furthermore been corrected in patch 12.2.1. Some related issue might occur with .xls files though, or so I suspected, so given that the customer mentioned above (if indeed having Office 2008) had an earlier version, I requested them to patch, test again and give me feedback - which I'm still waiting on.

Another user with problem opening the files had Excel X for Macintosh installed. In his case, Excel crashed without giving any error message when trying to open the files. With the bug above in mind I requested of him to patch it. Instead, he purchased Office 2008, patched it, and could then open the generated excel files without any problem.

I have a file I would gladly post, but not seeing any way to do so on the forum. Here's a url to it instead: http://www.morotsmedia.se/municipalities.xls

The issue might in other words be solved simply by keeping the software up to date, which IMO people ought to do.... Some remaining uncertainity about the first customer of mine though. 

Coordinator
Oct 7, 2010 at 12:50 PM

I don't have a Mac on hand. Hope zhunter can help you.

Mar 1, 2011 at 12:22 AM
Edited Mar 1, 2011 at 12:22 AM

We are currently experiencing this same problem with version 1.2.3 of the NPOI dll and Excel 2004 for Macs.  Some of our customers don't have the ability to upgrade to MS Office 2008 or even use OpenOffice as an alternate solution.  Is there any way this can be fixed?  I'm not using any macros or advanced functionality.  I make use of the CellStyle classes for formatting dates, times, numbers, text. etc., but otherwise it's a plain worksheet.

Any help is greatly appreciated, I really would like to avoid having to use another exporting component.

Thanks,

 

Denis

Coordinator
Mar 20, 2011 at 6:58 AM

The issue should not be similar to poi bug 47559 because bug 47559 is totally about xlsx file.