B4J Question XLUtils - Add comment to Cell [Solved]

LGS

Member
Licensed User
Longtime User
Hello everyone.
Is it possible to add comments to a specific cell?
Something like that:



Thanks in advance.
Luis
 
Solution


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 =...

Erel

B4X founder
Staff member
Licensed User
Longtime User


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))
End Sub

Based on: https://stackoverflow.com/a/53059793
 
Upvote 0
Solution

LGS

Member
Licensed User
Longtime User
Effective and efficient solution.
Erel, Thank you very much for your customary and continuous support to the community.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…