Can you show us the code that you used, specifically the POI code?
Main Topics
Browse All TopicsI am using Apache POI with Cold Fusion to generate Excel files. I am using an Excel file as a template that contains all my formatting. When I write data to this file, my styles are lost. How can I preserve the styles in the template?
Thanks...
Apache POI 3.0 RC4
Excel 2003
Windows XP
ColdFusion MX 7
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Ben nadel has some good post about CF and poi:
http://www.bennadel.com/bl
Here are two snippets of the POI code mixed with Cold Fusion:
==========================
<cfscript>
fileIn = createObject("java","java.
fs = createObject("java","org.a
wb = createObject("java","org.a
format = wb.createDataFormat();
sheet = wb.getSheetAt(0);
currencyStyle = wb.createCellStyle();
currencyStyle.setDataForma
</cfscript>
==========================
...
==========================
<cfquery datasource="RMSDev" name="getData">
...
</cfquery>
<cfset colHeaderNames = ArrayToList(getData.getCol
<cfset oCnt = 0>
<cfloop query="getData">
<cfset row = sheet.createRow(#evaluate(
<cfset iCnt = 0>
<cfloop index="x" list="#colHeaderNames#">
<cfset cell = row.createCell(#evaluate(i
<cfif left(x,2) eq "N_">
<cfif #evaluate("getData." & x)# neq "">
<cfset cell.setCellValue(#javacas
<cfif left(x,4) eq "N_C_">
<cfset cell.setCellStyle(currency
</cfif>
<cfelse>
<cfset cell.setCellValue("")>
</cfif>
<cfelse>
<cfset cell.setCellValue(#evaluat
</cfif>
<cfset iCnt = iCnt + 1>
</cfloop>
<cfset oCnt = oCnt + 1>
</cfloop>
<!--- Write the output to a file --->
<cfset fileOut = createObject("java","java.
<cfset wb.write(fileOut)/>
<cfset fileOut.close()/>
==========================
Flea2007
Try to avoid the function evaluate! most of the time you don't need it.
<cfset oCnt = 0>
<cfloop query="getData">
<cfset row = sheet.createRow(oCnt)/>
<cfset iCnt = 0>
<cfloop index="x" list="#colHeaderNames#">
<cfset cell = row.createCell(iCnt)/>
<cfif left(x,2) eq "N_">
<cfif getData[x] neq "">
<cfset cell.setCellValue(javacast
<cfif left(x,4) eq "N_C_">
<cfset cell.setCellStyle(currency
</cfif>
<cfelse>
<cfset cell.setCellValue("")>
</cfif>
<cfelse>
<cfset cell.setCellValue(getData[
</cfif>
<cfset iCnt = iCnt + 1>
</cfloop>
<cfset oCnt = oCnt + 1>
</cfloop>
The currency formatting works for me. Though I assume you're overwriting the existing styles by using createCell() instead of getCell().
You don't need the oCnt variable and you can reference the query value using the syntax:
queryName[columnName][rowN
<cfloop query="getData">
<cfset row = sheet.createRow(javacast("
<cfset iCnt = 0>
<cfloop index="x" list="#colHeaderNames#">
<cfset cell = row.createCell(javacast("i
<cfif left(x,2) eq "N_">
<cfif getData[x][currentRow] neq "">
<cfset cell.setCellValue(javacast
<cfif left(x,4) eq "N_C_">
<cfset cell.setCellStyle(currency
</cfif>
<cfelse>
<cfset cell.setCellValue("")>
</cfif>
<cfelse>
<cfset cell.setCellValue(getData[
</cfif>
<cfset iCnt = iCnt + 1>
</cfloop>
</cfloop>
You can also use the queryName.columnList variable instead of the undocumented method: queryName.getColumnList() .
Here's an array based version:
<cfset colHeaderArray = listToArray(getData.column
<cfloop query="getData">
<cfset row = sheet.createRow(javacast("
<cfloop from="1" to="#ArrayLen(colHeaderArr
<cfset colName = colHeaderArray[colNum]>
<cfset colValue = getData[colHeaderArray[col
<cfset cell = row.createCell(javacast("i
<cfif left(colName, 2) eq "N_">
<cfif colValue neq "">
<cfset cell.setCellValue(javacast
<cfif left(colName,4) eq "N_C_">
<cfset cell.setCellStyle(currency
</cfif>
<cfelse>
<cfset cell.setCellValue("")>
</cfif>
<cfelse>
<cfset cell.setCellValue(colValue
</cfif>
</cfloop>
</cfloop>
Business Accounts
Answer for Membership
by: CEHJPosted on 2007-06-29 at 12:28:15ID: 19392909
And the question is ..?