Blog

CFSPREADSHEET action=”write” java.lang.NullPointerException error

June 7, 2016

Came across some odd CFSPREADSHEET behavior in ColdFusion.

I was attempting to quickly export a query object to an Excel spreadsheet:

<cfset tmpXLSFile = "#getTempDirectory()#data_export.csv">
<cfspreadsheet action="write" overwrite="true" filename="#tmpXLSFile#" query="exportData">

ColdFusion kept throwing this strange error:

An exception occurred while using action="write" java.lang.NullPointerException

Everything seemed ok with my code and my query.

After some head scratching I noticed that my file variable had a .CSV extension. Changing this to XLS fixed the issue immediately:

<cfset tmpXLSFile = "#getTempDirectory()#data_export.xls">
<cfspreadsheet action="write" overwrite="true" filename="#tmpXLSFile#" query="exportData">

Not sure why ColdFusion cares about the file extension.

2 Comments

Ken
KenOctober 21, 2016 at 10:50:00 am

Thanks for posting this, just what was needed to resolve it for us too.

Melissa
MelissaAugust 1, 2018 at 12:12:46 pm

Thank you! Solved my issue.

Leave Your Comment

Your email address will not be published. Required fields are marked *


about me

An information technology professional with twenty four years experience in systems administration, computer programming, requirements gathering, customer service, and technical support.