0

I am using Ben Nadel's POIUtility.cfm to read and write to Excel files. There are some files which I can read very easily using the given code/file. But for some other files, I keep getting an instantiation error. I cannot figure out what's going wrong.

Code:

<cfset arrSheets = objPOI.ReadExcel( 
    FilePath = ExpandPath( "./File giving error.xls" ),
    HasHeaderRow = true
    ) />

Error:

Object instantiation exception.

An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class.

I'm using CF10, site hosted locally on IIS. Link to sample file.

Object instantiation exception

Leigh
  • 28,765
  • 10
  • 55
  • 103
  • 2
    CF10 has spreadsheet tags. Are you sure you actually need to use the POI? – Dan Bracuk Feb 03 '17 at 15:26
  • Your screenshots mention ColdFusion 7 – James A Mohler Feb 03 '17 at 17:37
  • (Like we've all said, CF10 already has spreadsheet support baked in. So if you're converting a legacy app, you might want to upgrade the code.) To answer your question - if you look at the stack trace - the error message says the file format isn't supported : *The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. POI only supports BIFF8 format (From Excel 97/2000/.....)*? What happens if you try reading it with CF10's [SpreadSheetRead](https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-s/spreadsheetread.html) function? – Leigh Feb 03 '17 at 18:03

1 Answers1

0

Short answer:

The format of the file you are trying to read is too old (Excel 95). POI only supports Excel 97 and later. Unless you really have files in that old format, I would not worry about it.

Given that spreadsheet functions are built into CF 10, you probably do not even need the POIUtility.

Longer answer:

If you look at the end of the stack trace, the "caused by" message explains that the format Excel 95 (BIFF5), is not supported. (It is over twenty years old!). For that file to be compatible with POI, you would need to it with another tool, like Excel, and save it in Excel 97 format (or later).

Caused by: org.apache.poi.hssf.OldExcelFormatException: The supplied spreadsheet seems to be Excel 5.0/7.0 (BIFF5) format. POI only supports BIFF8 format (from Excel versions 97/2000/XP/2003)

As an aside, the POIUtility was originally designed back in the days of ColdFusion 7, because it had no official support for manipulating spreadsheets. However, CF7 did include the POI library. So that component was written to fill the gap. Then along came CF9, which had spreadsheet functions already baked in, so the component became less necessary.

Leigh
  • 28,765
  • 10
  • 55
  • 103