B4J Question [SOLVED] XLUTILS - Request for insert an image to excel cell comment

moore_it

Well-Known Member
Licensed User
Longtime User
hi,
XLUtils does not include the possibility of using the setbackgroundimage method to insert a picture in the excel cell comments.
Is there anyone who can help me?

Thank you.


B4X:
Private Sub AddComment (sheet As XLSheetWriter, address As XLAddress, CommentText As String,w As Int,y As Int)
    Dim factory As JavaObject = sheet.Workbook.jWorkbook.RunMethod("getCreationHelper", Null)
    Dim cell As PoiCell = sheet.GetCell(address)
    Dim anchor As JavaObject = factory.RunMethod("createClientAnchor", Null)
    anchor.RunMethod("setCol1", Array(address.Col0Based + 1))
    anchor.RunMethod("setCol2", Array(address.Col0Based + 7))
    anchor.RunMethod("setRow1", Array(address.Row0Based + 1))
    anchor.RunMethod("setRow2", Array(address.Row0Based + 12))
    anchor.RunMethod("setDx1", Array(w))
    anchor.RunMethod("setDx2", Array(w))
    anchor.RunMethod("setDy1", Array(y))
    anchor.RunMethod("setDy2", Array(y))
    Dim drawing As JavaObject = sheet.PoiSheet.As(JavaObject).RunMethod("createDrawingPatriarch", Null)
    Dim comment As JavaObject = drawing.RunMethod("createCellComment", Array(anchor))
    'Dim pcidx As Int = sheet.Workbook.jWorkbook.RunMethod("addPicture",Array(by,sheet.workbook.xl))
    'comment.RunMethod("setBackgroundImage",Array(pcidx))
    comment.RunMethod("setString", Array(factory.RunMethod("createRichTextString", Array(CommentText))))
    'rowvalues(rowvalues.Length-2),rowvalues(rowvalues.Length-1)
    cell.As(JavaObject).RunMethod("setCellComment", Array(comment))
    Dim pcidx As Int = sheet.Workbook.PoiWorkbook.AddImage(File.DirTemp,CommentText)
    comment.RunMethod("setBackgroundImage",Array(pcidx))
End Sub

 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
I don't think I understood if what I would like to do is possible.
Is it better to think about using another tool?

Thank you

 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Works fine here:


B4X:
Private Sub AddComment(sheet As XLSheetWriter, address As XLAddress, CommentText As String)
    Dim factory As JavaObject = sheet.Workbook.jWorkbook.RunMethod("getCreationHelper", Null)
    Dim cell As PoiCell = sheet.GetCell(address)
    Dim anchor As JavaObject = factory.RunMethod("createClientAnchor", Null)
    anchor.RunMethod("setCol1", Array(address.Col0Based + 1))
    anchor.RunMethod("setCol2", Array(address.Col0Based + 3))
    anchor.RunMethod("setRow1", Array(address.Row0Based + 1))
    anchor.RunMethod("setRow2", Array(address.Row0Based + 5))
    Dim drawing As JavaObject = sheet.PoiSheet.As(JavaObject).RunMethod("createDrawingPatriarch", Null)
    Dim Comment As JavaObject = drawing.RunMethod("createCellComment", Array(anchor))
    Comment.RunMethod("setString", Array(factory.RunMethod("createRichTextString", Array(CommentText))))
    cell.As(JavaObject).RunMethod("setCellComment", Array(Comment))
    Dim pcidx As Int = sheet.Workbook.PoiWorkbook.AddImage(File.DirAssets, "logo.jpg") 'change here
    Comment.RunMethod("setBackgroundImage",Array(pcidx))
End Sub

B4X:
Dim workbook As XLWorkbookWriter = xl.CreateWriterBlank
Dim sheet As XLSheetWriter = workbook.CreateSheetWriterByName("Sheet 1")
sheet.PutString(xl.AddressName("A1"), "Comment here")
AddComment(sheet, xl.AddressName("A1"), "this is a test")
 
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
Hi Erel thanks for support but not work for me.
B4X:
    XL.Initialize
    'XL.BlankWorkbookIs2007 = False
    Dim Workbook As XLWorkbookWriter = XL.CreateWriterBlank
    'Log(Workbook.VersionName)
    Dim sheet1 As XLSheetWriter = Workbook.CreateSheetWriterByName(sheetName)

B4X:
Private Sub AddCommentNew(sheet As XLSheetWriter, address As XLAddress,path As String)
    Dim factory As JavaObject = sheet.Workbook.jWorkbook.RunMethod("getCreationHelper", Null)
    Dim cell As PoiCell = sheet.GetCell(address)
    Dim anchor As JavaObject = factory.RunMethod("createClientAnchor", Null)
    anchor.RunMethod("setCol1", Array(address.Col0Based + 1))
    anchor.RunMethod("setCol2", Array(address.Col0Based + 3))
    anchor.RunMethod("setRow1", Array(address.Row0Based + 1))
    anchor.RunMethod("setRow2", Array(address.Row0Based + 5))
    Dim drawing As JavaObject = sheet.PoiSheet.As(JavaObject).RunMethod("createDrawingPatriarch", Null)
    Dim Comment As JavaObject = drawing.RunMethod("createCellComment", Array(anchor))
    Comment.RunMethod("setString", Array(factory.RunMethod("createRichTextString", Array(path))))
    cell.As(JavaObject).RunMethod("setCellComment", Array(Comment))
    Dim m As Map = Globals.getFilePathAndName(path)
    Dim pcidx As Int = sheet.Workbook.PoiWorkbook.AddImage(m.Get("Path"),m.Get("Name"))
    'Dim pcidx As Int = sheet.Workbook.PoiWorkbook.AddImage(File.DirAssets, "logo.jpg") 'change here
    Comment.RunMethod("setBackgroundImage",Array(pcidx))
End Sub

 
Upvote 0

moore_it

Well-Known Member
Licensed User
Longtime User
Waiting for debugger to connect...
Program started.
Error occurred on line: 861 (Main)
java.lang.RuntimeException: Method: setBackgroundImage not found in: org.apache.poi.xssf.usermodel.XSSFComment
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:673)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:240)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:64)
at b4j.example.main._addcommentnew(main.java:121)
at b4j.example.main$ResumableSub_DataToXLSNew.resume(main.java:2026)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:47)
at jdk.internal.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:237)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at jdk.internal.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:42)
at anywheresoftware.b4a.keywords.Common$2$1.run(Common.java:1104)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:832)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…