简体   繁体   English

LibreOffice Base 表单:填充表格或网格控件未绑定到数据源

[英]LibreOffice Base form: filling table or grid control not bound to data source

I have a LibreOffice Base DB with a form and a table control on it.我有一个带有表单和表格控件的 LibreOffice Base DB。 There is a macro that gets some data to put in the table.有一个宏可以获取一些数据以放入表中。 The table is not bound to a data source and it has 1 column "id".该表未绑定到数据源,它有 1 列“id”。 I try the following code to add a row to empty table:我尝试使用以下代码向空表添加一行:

oFormTasks = oCurrentDocument.Forms.getByName("form_tasks")
oGridTasksNotDone = oFormTasks.getByName("grid_tasks_not_done")
oRowSetTasksNotDone = oGridTasksNotDone.getRowSet()
oRowSetTasksNotDone.insertRow()

and get "Function sequence error".并得到“功能序列错误”。 What is the correct way to add rows to the table?向表中添加行的正确方法是什么? If it is not possible, can I use some kind of grid control?如果不可能,我可以使用某种网格控件吗? I need it in a form, not in a dialog.我需要它的形式,而不是对话框。 在此处输入图像描述

From https://wiki.documentfoundation.org/images/b/b0/BH5009-Macros.pdf :https://wiki.documentfoundation.org/images/b/b0/BH5009-Macros.pdf

For a new record there is a special method, comparable with changing to a new row in a table control.对于新记录,有一种特殊的方法,类似于在表控件中更改为新行。 This is done as follows:这是按如下方式完成的:

  1. Prepare for a new record: oForm.moveToInsertRow()准备新记录: oForm.moveToInsertRow()
  2. Enter all wanted/required values.输入所有想要/需要的值。 This is done using the updateXxx methods as shown in the previous section.这是使用上一节中所示的updateXxx方法完成的。
  3. Confirm the new data with the following command: oForm.insertRow()使用以下命令确认新数据: oForm.insertRow()
  4. The new entry cannot be easily reversed.新条目不能轻易撤消。 Instead you will have to delete the new record.相反,您将不得不删除新记录。

EDIT :编辑

Let's start with some background information and then I'll offer a solution.让我们从一些背景信息开始,然后我将提供一个解决方案。

The method getRowSet() is misleading, because the table control itself does not have a rowset. getRowSet()方法具有误导性,因为表控件本身没有行集。 Instead, the method gets the rowset of the form that contains the table control.相反,该方法获取包含表控件的窗体的行集。

Unlike list or combo boxes, it seems that table controls that are unbound cannot have data.与列表或组合框不同,似乎未绑定的表格控件不能有数据。 It's possible to do columnNames = oGridTasksNotDone.ElementNames but that's about all.可以执行columnNames = oGridTasksNotDone.ElementNames ,但仅此而已。

You can create an UNO grid control in a dialog with code such as oGridModel.GridDataModel = oDataModel , but that will not work in a form.您可以使用oGridModel.GridDataModel = oDataModel类的代码在对话框中创建 UNO 网格控件,但这在表单中不起作用。

A Base form document can contain multiple independent forms by going to Form -> Form Navigator .一个基本表单文档可以包含多个独立的 forms 通过转到Form -> Form Navigator Note that I am not talking about subforms or a different form document, but rather for example "Form1", "Form2" in the navigator.请注意,我不是在谈论子表单或不同的表单文档,而是在导航器中谈论例如“Form1”、“Form2”。 This allows data to be used in the same document that is not necessarily related to each other.这允许在不一定彼此相关的同一文档中使用数据。

To me, the obvious solution is to create a table "Table2" that will be used only for the table control.对我来说,显而易见的解决方案是创建一个仅用于表控件的表“Table2”。 As explained in the previous paragraph, create a separate toplevel form "Form2" to handle the table control, and set its recordset source to be Table2.如上一段所述,创建一个单独的顶级表单“Form2”来处理表格控件,并将其记录集源设置为 Table2。 Then a macro can populate the table control:然后一个宏可以填充表格控件:

  1. delete all records from the recordset of Form2 (which is Table2)从Form2的记录集中删除所有记录(即Table2)
  2. gather data from Form1 (based on Table1 or Query1 or whatever other data is involved)从 Form1 收集数据(基于 Table1 或 Query1 或涉及的任何其他数据)
  3. insert rows using the recordset of Form2使用 Form2 的记录集插入行

Alternatively, if it is required not to use bound controls, you could create Text Tables on the form ( Table -> Insert Table ) and write macros to insert values into them.或者,如果需要不使用绑定控件,您可以在表单上创建文本表( Table -> Insert Table )并编写宏以将值插入其中。

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM