Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpreadsheetAddImage(SpreadsheetObj, imageData, imageType, anchor) : problem #43

Open
dgiet opened this issue Feb 29, 2012 · 1 comment

Comments

@dgiet
Copy link

dgiet commented Feb 29, 2012

Error
Railo 3.3.1.000 Error (expression)
Message No matching Method/Function for org.apache.poi.hssf.usermodel.HSSFWorkbook.addPicture(struct, numeric) found
Stacktrace The Error Occurred in
C:\DataSites\pfizer\WEB-INF\railo\components\org\cfpoi\spreadsheet\Spreadsheet.cfc: line 437

435: </cfif>
436:
437: <cfset imageIndex = getWorkbook().addPicture(bytes, JavaCast("int", imgTypeIndex)) />
438:
439: <cfset theAnchor = loadPoi("org.apache.poi.hssf.usermodel.HSSFClientAnchor").init() />

called fromC:\DataSites\pfizer\WEB-INF\railo\library\function\SpreadsheetAddImage.cfm: line 24

called fromC:\DataSites\pfizer\front\templates\export_xls.cfm: line 305

when using this code

<cfset s = spreadsheetNew()>
<cfset headersRows = Replace(ColRealNameListe, "&nbsp;", " ", "ALL")>
<cfset i=1>

<!--- Add header row --->
<cfset spreadsheetAddRow(s, "#headersRows#")>
<cfset SpreadSheetSetColumnWidth(s, 1, 26)>
<cfset SpreadSheetSetColumnWidth(s, 2, 26)>
<cfset SpreadSheetSetColumnWidth(s, 3, 26)>
<cfset SpreadSheetSetColumnWidth(s, 4, 26)>
<cfset SpreadSheetSetColumnWidth(s, 5, 26)>
<!--- format header --->    
<cfset spreadsheetFormatRow(s,
        {
            bold="true",
            fgcolor="lemon_chiffon",
            fontsize="10"
        },
        1)>

<!--- Add query <cfset spreadsheetAddRows(s, QListe)> --->
<cfset nb_cols = ListLen(variables.colQListe)>
<cfloop query="QListe">
    <cfset i = i+1>
<cfset j=0>
    <cfloop index="t" list="#variables.colQListe#">
        <cfset spreadsheetAddRow(s, "")>
        <cfset SpreadSheetSetRowHeight(s, #i#, 148)>
        <cfset j = j+1>
        <cfif findnocase("thumb", t) NEQ 0>
            <cfif findnocase("jpg", #QListe[t][QListe.currentrow]#) NEQ 0>
                <!--- Create a ColdFusion image from an existing JPEG file. ---> 
                <cfimage source="C:/pfizer/mini_thumbs/white.jpg" name="myBgImage"> 
                <!--- Create a ColdFusion image from an existing JPEG file. ---> 
                <cfimage source="#QListe[t][QListe.currentrow]#" name="myImage"> 
                <!--- Retrieve the height of the image. ---> 
                <cfset imgHeight=#ImageGetHeight(myImage)#>
                <!--- Retrieve the width of the image. ---> 
                <cfset imgWidth=#ImageGetWidth(myImage)#>
                <cfif imgWidth LT 148>
                    <cfset xCorner = (148-#imgWidth#)/2>
                <cfelse>
                    <cfset xCorner = 0>
                </cfif>
                <cfif imgHeight LT 148>
                    <cfset yCorner = (148-#imgHeight#)/2>
                <cfelse>
                    <cfset yCorner = 0>
                </cfif>
                <!--- Paste myImage centered over myBgImage. ---> 
                <cfset ImagePaste(myBgImage,myImage,xCorner,yCorner)> 

                <cfset SpreadsheetAddImage(s, myBgImage, "jpg", "0,0,26,26,#i#,#j#,#i+1#,#j+1#")>
            <cfelse>
                <cfset SpreadsheetSetCellValue(s, "#QListe[t][QListe.currentrow]#", "#i#", "#j#")>
            </cfif>
        <cfelse>
            <cfset SpreadsheetSetCellValue(s, "#QListe[t][QListe.currentrow]#", "#i#", "#j#")>
        </cfif>
    </cfloop>
</cfloop>

All except the line <cfset SpreadsheetAddImage(s, myBgImage, "jpg", "0,0,26,26,#i#,#j#,#i+1#,#j+1#")> works fine

Thanks for your help
Didier Giet

@Leigh-
Copy link

Leigh- commented Mar 2, 2012

SpreadsheetAddImage is not handling things properly when you pass in an image object, rather than a file path. A temporary work around is to pass in the bytes of the image object instead.

<cfset imageBytes = ImageGetBlob(myBgImage)>
<cfset SpreadsheetAddImage(s, imageBytes, "jpg", "0,0,26,26,#i#,#j#,#i+1#,#j+1#")>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants