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:

1668000462126.png


Thanks in advance.
Luis
 
Solution
1668061192418.png


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
1668061192418.png


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
Top