As you have discovered, this happens with the ColdFusion <cfspreadsheet/> because it creates the entire document in memory, which leads to JVM OutOfMemory errors. What you need is what dumps buffers to disk so that you don't run out of memory. This offers a CSV that is much easier to buffer. I suppose there are ways to do this with Excel too, but I don't know them.
So, for you there are two options:
- use java library
- use the ColdFusion methods
fileOpen() , fileWrite() , fileClose()
I will cover each one in turn.
Java libary
opencsv is my preference. This assumes, of course, that you know how to configure .jar in the ColdFusion path. If you do this, it is a question using its API to open the file and provide data for each line. It is very simple. Check his documents for examples.
ColdFusion Methods
Be warned that there are dragons here .
If you export numbers or strings that do not contain double quotes or commas, you can probably do this. If not, find out what to avoid and why you use the library in the first place. The code is something like this:
<cfset csvFile = fileOpen(filePath, 'read')> <cfloop query="yourQuery"> <cfset csvRow = ""> <cfset fileWrite(csvFile, csvRow)> </cfloop> <cfset fileClose(csvFile)>
If the query data you are working with is also large, you can deal with a nested loop to cut it out.
source share