Skip to main content
Known Participant
February 17, 2016
Question

Cast error trying to read an excel spreadsheet with cfspreadsheet

  • February 17, 2016
  • 1 reply
  • 2806 views

I'm trying to read an Excel spreadsheet using CF spreadsheet and keep getting the error below.

java.lang.ClassCastException: org.apache.poi.xssf.usermodel.XSSFRichTextString cannot be cast to org.apache.poi.hssf.usermodel.HSSFRichTextString

Here is the line of code that causes the error:

<cfspreadsheet action="read" src = "#xfile#" sheetname="Pilot Instructions" name="pilot_sheet">

This is CF 11 running in IIS. Any thoughts on why this error is being generated?

Thanks

DW

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
February 27, 2016

XLSX and XLS are processed by different parts of the POI engine. XSSF implies XLSX and HSSF implies XLS.

So the error message suggests that you may be attempting to pass off an XLSX file as XLS. Did you, for example, save an XLSX file in XLS format?

dwright65Author
Known Participant
February 29, 2016

I didn't create the file, so I'm not sure which format is the true format. The file that I read in was XLSX, so I changed the extension to XLS to see if that would make any difference, but I received the same error. In further testing, I realized that my first post gave the incorrect line of code that was throwing the error. It wasn't the read command, but the update command immediately following:

<cfspreadsheet action="read" src = "#xfile#" sheetname="Pilot Instructions" name="pilot_sheet">

<cfspreadsheet action="update" filename="#new_file#" sheetname="Pilot Instructions" name="pilot_sheet" password="pwd">

You were the one trying to help with the issue that I had with my spreadsheet reading in all three sheets at once instead of one-at-a-time and couldn't get the password to work. This is the same spreadsheet. What I attempted to do here was to create a file from scratch with a dummy sheet in it, read the other file and use the update function to add the three sheets that I needed and then delete the dummy sheet. Everything works just fine until I try using this specific Excel file. Is it possible that this file is corrupted in some way that it opens fine in Excel, but other apps have issues? Or, could it be that there it is a bit too complicated? There are some hidden sheets and other non-standard types of things in it.

Thanks

DW

BKBK
Community Expert
Community Expert
March 1, 2016

I can help test the file. I sent you my e-mail address.