HSSFCellStyle count : is there any limitation? - apache-poi

I'm creating a HSSFWorkbook and I'm wondering if there is any limitation about the number of HSSFCellStyle that a HSSFWorkbook can contain ?

It's not a HSSF requirement per-se, it's a requirement imposed by the Excel .xls file format.
Apache POI provides an easy way to get the limits of a given Excel file format, through the class SpreadsheetVersion. The method you'll want is getMaxCellStyles()
From that, you can discover that the maximum number of Cell Styles in a given .xls (HSSF) Excel workbook is 4000.
You can also get the same information from the Microsoft documentation, the pages are this for Excel 2003 / .xls and this for Excel 2007 / .xlsx

Related

How do you make a workbook or worksheet read only using SpreadsheetML / Excel 2003 XML?

I am using SpreadsheetML to generate an Excel spreadsheet with multiple worksheets.
I would like to make the document read only when opened with Excel. How can I do this?
(I appreciate that a user could open the XML file as text and do what they want with it so this is read-only in the loosest sense.)
Thanks
Spreadsheet ML references:
https://en.wikipedia.org/wiki/Microsoft_Office_XML_formats#Excel_XML_Spreadsheet_example
http://m8y.org/Microsoft_Office_2003_XML_Reference_Schemas/Help/html/spreadsheetml_HV01151864.htm
https://en.wikipedia.org/wiki/SpreadsheetML

using MS XLSB instead of MS XLS

I need opinion on switching from MS XLS to XLSB. I have several models on MS xls file (Microsoft Excel 97-2003 Worksheet .xls) and have been using those models since many years. The xls files has lot of data, it has formula, macros, add-ins, formula to pull data from databases such as Bloomberg, Factset or Haver. I am planning to shift the model from MS Xls to MS xlsb i.e. binary format, however want to be sure if everything would work fine in binary format.
Can you please let me know if MS xls files are completely compatible with MS xlsb? ? Is there any disadvantage of using XLSB? Would be really thankful for your help.
XLS and XLSB are different file formats. The big disadvantage of XLSB is that it only works in Excel 2007+, so you can't depend on add-ins that only work in Excel 2000.
If your file works correctly in Excel 2007 or 2010 or 2013, then XLSB will preserve every feature from the XLS. This is different from XLSX, where many features are intentionally omitted.

Using Excel Macros in both XLS and XLSX

How can i use the same macro in both the XLS and XLSX formats?
Is there anyhthing to be added in the XLSX format. i have written a small macro in XLSX (it has last column XFD) i want to use it in the XLS (it has last column as IV) .Is there anything to be changed?
This question is not about converting the file formats.
XLSX provides a broader set of formulas and also VBA functionality. Additionally, XLSX expands the row/column restriction that exists before Excel 2007 (from 256 columns to 16,384).
If your macros are written using up to column 16,384 (XFD), you're going to have to perform the calculations in chunks to make them fit within the 256 column (IV) restriction of Excel 2003. If you're using variables and not writing everything to a sheet, then there should be no problem (barring running out of memory).
Without more detail, it's difficult to tell whether you're using a set of functions from Excel 2007 that may not be supported in Excel 2003.
Which format was it written first? normally it should work in both formats of excel. As you are referring to last cell of both formats, it seems to have a code level issue than a version lavel.

Opening Excel with many columns

Basically, I have an Excel 2003 spreadsheet that I wish to open.
However, it is giving error because it has too many columns.
What is a way of opening this Excel file to view the entire data?
PS. I have Excel 2010 installed as well but unable to open that file.
Additional info: The Excel file is created using SSRS -> Export to Excel. The number of columns in the report varies and when large report range is chosen, it will have "too many" columns.
If you have more than 256 columns you won't be able to use versions of Excel prior to 2007.
It sounds like you're exporting to a pre-2007 workbook (xls) with more than that number.
in 2007+ you can have around 16 thousand columns.
This page has details about how to export to a 2007+ file format (xlsx):
http://msdn.microsoft.com/en-us/library/dd255234(v=sql.110).aspx
Note I think your SQL server may need to be a certain version to use the 2007+ excel renderer, but I have little experience there.

Identifying Different Excel File Formats

Is anyone familiar with a library or tool that can determine which format an excel file is in? Or, failing that, documentation on the different formats that would allow me to write my own?
The Excel file format is called the Binary Interchange File Format (BIFF) there are different versions of Excel that use the same version of BIFF.
Open Office document on the Excel File Format.
Take a look at the Open Office API, this should help you.
Excel 97-2003 workbooks are known as Biff8. They are actually OLE Compound documents which are essentially a file system within a file. They store the main workbook in a stream named "Workbook" and they have other streams for VBA modules, OLE objects, document properties, etc...
Win32 includes APIs for reading OLE Compound Documents. They are far from trivial. Once you get the "Workbook" stream, the first Biff record identifies the file as being an Excel file.
You can find excellent documentation from Microsoft on the Biff8 file format on the Microsoft Office Binary File Formats page.
The new Excel 2007 Open XML (xlsx) format is actually a zip file with workbook parts and is documented at OpenXmlDeveloper.org.
I am not aware of a tool which will simply tell you the format of a workbook. You could take the easy, but not very reliable approach of just looking at the extension which will be right 99%+ of the time - if accuracy is not an issue.
There are many tools to read xls and xlsx workbooks, including SpreadsheetGear for .NET which reads both.
Disclaimer: I own SpreadsheetGear LLC

Resources