basic - 在 LibreOffice Calc 中插入带有基本宏的单元格

标签 basic libreoffice-calc uno

我正在尝试插入一个从范围中的第一个单元格开始的单元格(通过文档事件工作表的 .getCellRangeByName() 方法)。

我发现了如何使用 OpenOffice 库 (.uno:InsertCell) 中的调度程序来执行此操作,但如果可能的话,我更愿意使用不需要调度程序的东西。

我计划连接到按钮的示例代码...

Sub AddManualBalance(EntryDate As Date, EntryAmount As Currency)

    Dim Doc As Object
    Dim Sheet As Object
    Doc = ThisComponent
    If Doc Is Nothing Then
        Return
    EndIf
    Sheet = Doc.getCurrentController().getActiveSheet()
    If Sheet Is Nothing Then
        Return
    EndIf

    Dim TargetCells As Object
    TargetCells = Sheet.getCellRangeByName("B9:C9");

    // insert a cell in both the B and C columns at position 9,
    // then move all other cells down

    // add my EntryDate as a value to the new cell in B column
    // add my EntryAmount as a value to the new cell in C column

End Sub

预先感谢您的帮助!

附注我真的不喜欢 Basic,但似乎对于电子表格和办公应用程序自动化来说,这是首选语言。有没有办法用更类似于 C 的语言来执行 LibreOffice/OpenOffice 宏?

最佳答案

以下代码可以实现您想要的功能:

Dim Doc As Object
Dim Sheet As Object
Dim oDestCell As Object
Dim CellRangeAddress As New com.sun.star.table.CellRangeAddress

Doc = ThisComponent
Sheet = Doc.Sheets(0)

CellRangeAddress.Sheet = 0
CellRangeAddress.StartColumn = 1
CellRangeAddress.StartRow = 8
CellRangeAddress.EndColumn = 2
CellRangeAddress.EndRow = 8

Sheet.insertCells(CellRangeAddress, com.sun.star.sheet.CellInsertMode.DOWN)

oDestCell=Sheet.getCellByPosition(1,8)
oDestCell.setValue(EntryDate)

oDestCell=Sheet.getCellByPosition(2,8)
oDestCell.setValue(EntryAmount)

您可以在 api.libreoffice.org 上阅读有关 C++ 和 LibreOffice 的信息

关于basic - 在 LibreOffice Calc 中插入带有基本宏的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32488702/

相关文章:

basic - 如何在 commodore 64 basic 中分隔字符串?

visual-studio-code - 如何修复 Visual Studio Code 以便它运行和调试简单的基本脚本(.bas 文件)?

python - 使用 Python 在 LibreOffice 中加载 HTML 文件

java - OpenOffice 在 Java 中以编程方式使用 .odm

c - 6502 仿真器上的 EhBASIC 输入

windows - BASIC - 在按键上激活麦克风录音?

excel - 如何提取两个点之间的文本

macros - Libreoffice 计算 : loop throught cells macro

vba - 更快的单元格输入值 LibreOffice Vba

java - 使用 Openoffice Java API (UNO API) 将整个 ODT (Openoffice Writer) 文档部分复制到其他文档