java - Java 验证列表 Openoffice
问题描述
我正在尝试创建一个电子表格,并且我想将ValidationType
“ List
”应用于特定的单元格。
到目前为止,我这样做了:
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 天我一直在搜索,但我不知道我必须在哪里创建这个指定的列表以及如何应用它。
如果有人可以帮助我,我会更高兴。
先感谢您。
解决方案
调用方法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 页面。
推荐阅读
- c# - 如何将 UWP 连接到 MySQL?
- apache-spark - 尽管在 Spark Scala 中存在 Distinct,但区分大小写在数据帧中创建重复项
- java - RabbitMQ:无法通过 TLS 连接
- ios - ios14 Xcode 12 - 触摸 SwiftUI 对象时精灵不显示,但触摸 SKScene 时工作
- soapui - 从 Eclipse 运行 Soap Ui 脚本时无法在 Soap Ui 中使用测试套件属性
- python - Python Number Guessing Game 中的程序赢/输统计
- r - 关于r中的chron时间匹配
- swift - iPad Pro 上的 Swift 和 Core Data 性能
- r - 在 Rstudio 中用 ggplot2 命名 x 轴的问题
- python - Windows中调用python脚本时自动打开虚拟环境