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;
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();
// MemoryStream to client
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-Disposition", "attachment; filename=" + filename);