在对定制表单执行openoffice-base中的查询之后,我希望将选定的一组数据转换为一个模板openoffice表。我知道我可以通过按data (F4)按钮来访问openoffice中的数据集,但之后我只能通过查询访问数据集。最好的解决方案是在对表单进行数据库查询之后--一个按钮事件--从模板中打开openoffice表并从数据集中插入数据。
发布于 2016-02-22 22:59:27
首先,转到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.在Events选项卡中,单击Execute action旁边的三个点。单击Macro...并找到添加的Copy_Record_To_Calc宏。
现在关闭设计模式。转到记录并单击按钮。它将打开Calc模板,并将当前记录的前两列复制到电子表格的A和B列中。
另请参阅:
https://stackoverflow.com/questions/35527494
复制相似问题