Skip to content

Instantly share code, notes, and snippets.

Created July 29, 2016 14:28
Show Gist options
  • Save anonymous/7c1d815b3d134a5be5a0ee505918e2ff to your computer and use it in GitHub Desktop.
Save anonymous/7c1d815b3d134a5be5a0ee505918e2ff to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
workBook = CreateObject( "java", "org.apache.poi.xssf.usermodel.XSSFWorkbook").Init();
sheet = WorkBook.CreateSheet( JavaCast( "string", "my sheetname" ) );
// Simulate rows used in AC4 formula
sheet.createRow(0).createCell(0).setCellValue( javacast("float", 5) );
sheet.createRow(1).createCell(0).setCellValue( javacast("float", 7) );
// Simulate AC4 formula
sheet.createRow(2).createCell(0).setCellFormula( "SUM(A1:A2)" );
// Simulate cell populated by Oracle date
sheet.createRow(3).createCell(0).setCellValue( now() );
// Finally, apply EDATE formula
sheet.createRow(4).createCell(0).setCellFormula( "EDATE($A$4,-(A3))" );
// Using binary stream because trycf.com does not support files for security reasons
baos = createObject("java", "java.io.ByteArrayOutputStream").init();
workBook.write( baos );
baos.close();
</cfscript>
<!--- CF10 lacks support for script version of cfcontent --->
<cfheader name="Content-Disposition" value="inline; filename=test.xlsx">
<cfcontent type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
variable="#baos.toByteArray()#">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment