【问题标题】:Transfer a data set from openoffice base to calc将数据集从 openoffice base 传输到 calc
【发布时间】:2016-02-20 18:46:07
【问题描述】:

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

【问题讨论】:

  • 我不明白这个问题的几个部分。什么是“表单查询”? “模板 openoffice-calc 表”是否意味着 table AutoFormat?另外,我不确定您所说的所需按钮事件是什么意思。按钮在哪里——在基本表单上、在 Calc 中、在对话框或消息框中?当按钮被按下时,你想发生什么?
  • 使用“查询表单”是一个由查询助手创建的查询,该查询将由表单(使用表单助手创建)执行。您可以指定一个文档(在 calc 中)是一个模板,这很重要。基本表单上的按钮意味着当它被按下时,应该将数据传输到 calc 模板。 - 抱歉英语不好!
  • 好的,现在更清楚了。

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


【解决方案1】:

首先转到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 列中。

另见:

【讨论】:

    猜你喜欢
    • 2011-08-09
    • 1970-01-01
    • 2010-10-31
    • 1970-01-01
    • 2015-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    相关资源
    最近更新 更多