向宏中的单元格添加注释

时间:2010-07-10 15:53:56

标签: openoffice.org openoffice-calc

我想在宏中为单元格添加注释。我曾尝试录制宏来执行此操作,但它没有做任何事情。有任何想法吗?这是录制宏的内容:

dim document   as object
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:DrawEditNote", "", 0, Array())
rem dispatcher.executeDispatch(document, ".uno:InsertAnnotation", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:DrawEditNote", "", 0, Array())
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "ToPoint"
args4(0).Value = "$A$2"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args4())

1 个答案:

答案 0 :(得分:2)

在OpenOffice中,它被称为“插入注释”

' col, row - Zero-based
sub insertAnnotation(col, row, text)
    sheet = thiscomponent.getcurrentcontroller.activesheet
    cell = sheet.getCellByPosition(col, row) 
    sheet.Annotations.insertNew(cell.getCellAddress, text)
    cell.Annotation.isVisible = True
end sub

' row, col - Zero-based
sub removeAnnotation(col, row)
    sheet = thiscomponent.getcurrentcontroller.activesheet
    cell = sheet.getCellByPosition(col, row)
    cell.clearContents( com.sun.star.sheet.CellFlags.ANNOTATION )
end sub

insertAnnotation(2, 0, "Hello " & Now)