Okay. I got it working. Definitely some java strictness going on. And
being pretty much java stupid, I did much trial and error to get this
to work. I'll post code here and maybe blog it later so hopefully
anyone in the future can find it. Using jExcel, I was able to open an
existing spreadsheet, make a copy, put in an image an save the new
file.

<!--- Get java Input File of spreadsheet template --->
<cfset fileInput = createObject("java",
"java.io.File").init("c:\invoice.xls") />
<!--- Get instance of jExcel Workbook object --->
<cfset wb = createObject("java","jxl.Workbook") />
<!--- Read that File into the workbook object --->
<cfset wb1 = wb.getWorkbook(fileInput) />
<!--- Create an output file for copying to --->
<cfset fileOutput = createObject("java",
"java.io.File").init("c:\invoiceCopy.xls") />
<!--- Create a copy of the original workbook object --->
<cfset wb2 = wb.createWorkbook(fileOutput, wb1) />
<!--- Get the first sheet (zero based) in the workbook --->
<cfset sheet = wb2.getSheet(javaCast('int',0)) />
<!--- Get java Input File of the image --->
<cfset myImg = createObject("java",
"java.io.File").init("c:\CityBoyntonBeach.gif") />
<!--- Read that image into a java ImageIO object (allows us to get
width and height, etc.) --->
<cfset myInput = createObject("java","javax.imageio.ImageIO").read(myImg) />
<!--- Get instance of java ByteArrayOutputStream. This is used to
convert the image to PNG. Be sure to call init() here or things break.
--->
<cfset myBaos = createObject("java","java.io.ByteArrayOutputStream").init() />
<!--- Convert the image to PNG, storing it into the
ByteArrayOutputStream just instantiated. --->
<cfset ImageIO =
createObject("java","javax.imageio.ImageIO").write(myInput,
javaCast("string","PNG"), myBaos) />
<!--- Get the width and height of the image divided by some excel
default values. Without this the image is enlarged incorrectly --->
<cfset myWidth = myInput.getWidth() / 64 /> <!--- 64 is default width
of an excel cell (in pixels maybe?) --->
<cfset myHeight = myInput.getHeight() / 17 /><!--- 17 is default
height of an excel cell --->
<!--- Put image into a jExcel writable image object, parameters are
column number(zero based), row number (zero based), width, height,
image --->
<cfset wi = 
createObject("java","jxl.write.WritableImage").init(javaCast('double',1),
javaCast('double',0), javaCast('double',myWidth),
javaCast('double',myHeight), myBaos.toByteArray()) />
<!--- add the image to the sheet. --->
<cfset sheet.addImage(wi) />
<!--- Save and close. --->
<cfset wb2.write() />
<cfset wb2.close() />



-- 
Matt Williams
"It's the question that drives us."

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
CF 8 – Scorpio beta now available, 
easily build great internet experiences – Try it now on Labs
http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_adobecf8_beta

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:280484
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to