首页 > 解决方案 > Java 验证列表 Openoffice

问题描述

我正在尝试创建一个电子表格,并且我想将ValidationTypeList”应用于特定的单元格。

到目前为止,我这样做了:

public static void setValidationProperty(XCell cell)
{
    XPropertySet xPropertySet = UnoRuntime.queryInterface(XPropertySet.class, cell);
    XPropertySet xPropSet1 = null;
    XPropertySet xPropSet2 = null;
    xPropSet1 = UnoRuntime.queryInterface(XPropertySet.class, xPropertySet.getPropertyValue("Validation"));
    xPropSet2 = UnoRuntime.queryInterface(XPropertySet.class, xPropSet1);
    xPropSet2.setPropertyValue("Type", ValidationType.LIST);
    xPropSet2.setPropertyValue("ShowList", (short) 1);
    xPropSet2.setPropertyValue("IgnoreBlankCells", (Boolean) true); 
    xPropertySet.setPropertyValue("Validation", xPropSet2); 
}

类型的 OpenOffice 文档描述LIST是:

只有指定列表中的字符串才有效。

http://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/ValidationType.html#LIST

最近 3 天我一直在搜索,但我不知道我必须在哪里创建这个指定的列表以及如何应用它。

如果有人可以帮助我,我会更高兴。

先感谢您。

标签: javaopenoffice.orgopenoffice-calc

解决方案


调用方法setFormula1 ,如https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=25345中的 Basic 所示。

XPropertySet xPropertySet = UnoRuntime.queryInterface(
    XPropertySet.class, cell);
XPropertySet xValidPropSet = UnoRuntime.queryInterface(
    XPropertySet.class, xPropertySet.getPropertyValue("Validation"));
xValidPropSet.setPropertyValue("Type", ValidationType.LIST);
xValidPropSet.setPropertyValue("ShowList", (short) 1);
xValidPropSet.setPropertyValue("IgnoreBlankCells", (Boolean) true); 
XSheetCondition xCondition = (XSheetCondition)
    UnoRuntime.queryInterface(XSheetCondition.class, xValidPropSet);
xCondition.setOperator(ConditionOperator.EQUAL);
xCondition.setFormula1("\"1\";\"2\";\"3\"");
xPropertySet.setPropertyValue("Validation", xValidPropSet); 

(警告:我没有编译或测试过这段代码)。

另请查看显示 Java 代码的DevGuide 页面。


推荐阅读