0

在我通过自定义表单在 openoffice-base 中进行查询后,我想将一组选定的数据传输到模板 openoffice-calc 表中。我知道我可以通过按数据源 (F4) 按钮访问 openoffice-calc 中的数据集,但我只能通过查询访问。最好的解决方案是在对表单进行数据库查询之后,需要一个按钮事件来从模板打开 openoffice-calc 表并插入数据集中的数据。

4

1 回答 1

3

首先转到Tools -> Macros -> Organize Macros -> LibreOffice Basic并添加此代码。更改模板文件的路径。

Sub Copy_Record_To_Calc(oEvent)
    Dim oForm
    Dim templatePath As String
    Dim oServiceManager As Object, oDesktop As Object
    Dim oFileProperties As Object
    Dim oDoc As Object, oSheet As Object, oCell As Object
    Dim column As Integer
    oForm = oEvent.Source.getModel().getParent()
    If oForm.isAfterLast() Then
        Print "Hey, you are after the last element."
        Exit Sub
    ElseIf oForm.isBeforeFirst() Then
        Print "Hey, you are before the first element."
        Exit Sub
    End If
    templatePath = "file:///C:/Users/JimStandard/Desktop/Untitled 2.ots"
    Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
    Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
    Set oFileProperties(0) = new com.sun.star.beans.PropertyValue
    oFileProperties(0).Name = "AsTemplate"
    oFileProperties(0).Value = True
    Set oDoc = oDesktop.loadComponentFromURL( _
        templatePath, "_blank", 0, Array(oFileProperties))
    oSheet = oDoc.Sheets(0)
    For column = 1 to 2
        oCell = oSheet.getCellByPosition(column - 1, 0)
        oCell.String = oForm.getString(column)
    Next column
End Sub

然后在表单设计模式下,右键单击按钮并选择Control。在“事件”选项卡中,单击 旁边的三个点Execute action。单击Macro...并找到您添加的 Copy_Record_To_Calc 宏。

现在关闭设计模式。转到记录并单击按钮。它将打开 Calc 模板并将当前记录的前两列复制到电子表格的 A 列和 B 列中。

也可以看看:

于 2016-02-22T22:59:27.277 回答