将数据集从openoffice base传输到calc

时间:2016-02-20 18:46:07

标签: openoffice.org openoffice-calc openoffice-base

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

1 个答案:

答案 0 :(得分: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列。

另见: