[英]Programmatically check/uncheck values of a DataPilot row field with the uno library
I want to be able to programmatically filter a Calc DataPilot (pivot table) with C# or Java.我希望能够以编程方式使用 C# 或 Java 过滤 Calc DataPilot(数据透视表)。
At the moment, I am able to do the below:目前,我可以执行以下操作:
Pending:待办的:
Is this doable programmatically?这可以通过编程方式实现吗? If yes, what is the missing code to achieve this?
如果是,实现此目的缺少的代码是什么?
Current code当前代码
XSpreadsheetDocument xSpreadsheetDocument = (XSpreadsheetDocument)document;
XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
//mSheetName is the name of the sheet that has the DataPilot I want to filter
// get reference to the sheet that has my DataPilot
XSpreadsheet sheet = (XSpreadsheet)xSpreadsheets.getByName(mSheetName).Value;
//Get a reference to the DataPilot that I want to uncheck/check its row field values
XDataPilotTablesSupplier xSupplier = (XDataPilotTablesSupplier)sheet;
XDataPilotTables xSheetPilotTables = xSupplier.getDataPilotTables();
//mPivotTableName is the name of the DataPilot
uno.Any xDPTableObj = xSheetPilotTables.getByName(mPivotTableName);
XDataPilotTable xPilotTable = (XDataPilotTable)xDPTableObj.Value;
XDataPilotDescriptor xDPDesc = (XDataPilotDescriptor)xPilotTable;
// get available row fields
XNameAccess rowFields = (XNameAccess)xDPDesc.getRowFields();
//get the row field of interest
//mFieldName is the name of the row field
uno.Any xRowItemObj = rowFields.getByName(mFieldName);
Example: if we assume the xRowItemObj has 2 checked values (eg 1 and 2) how do I keep value 1 checked only?示例:如果我们假设 xRowItemObj 有 2 个检查值(例如 1 和 2),我如何只检查值 1?
So far, any research in forums and libreOffice Documentation did not return a result.到目前为止,论坛和 libreOffice 文档中的任何研究都没有返回结果。 I am not even sure if it is doable
我什至不确定它是否可行
Get the list of items from the row field.从行字段中获取项目列表。 Here is a Basic example that checks even-numbered boxes.
这是一个检查偶数框的基本示例。
oRowItem = oDPTable.getRowFields().getByIndex(0)
oItems = oRowItem.getItems()
For i = 0 To oItems.getCount() - 1
oItem = oItems.getByIndex(i)
If (i Mod 2 = 0) Then
oItem.setPropertyValue("IsHidden", False)
Else
oItem.setPropertyValue("IsHidden", True)
End If
Next
If you haven't yet, be sure to use an introspection tool such as MRI .如果您还没有,请务必使用MRI等内省工具。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.