OOo:UNO(Java)TrackedChanges:隐藏文档时如何接受(或隐藏)跟踪的更改?

时间:2012-02-28 17:26:51

标签: java openoffice.org dispatcher uno

我的问题:我编写了一个自动系统,需要读取.doc和.odt,对其执行一些操作并再次将其导出为pdf。

目前这对我需要的一切都很好,我可以解决所有问题,直到这个:

如果用户提供记录了更改的文档(红线),我需要自动接受所有更改或隐藏它们。

只要OOo在屏幕上显示,我就可以使用下面的代码来解决这个问题。当我把它隐藏起来时,我的电话什么都不做。

所以,这就是我现在所做的事情:

    // DO NOT try to cast this to Desktop as com.sun.star.frame.Desktop is NOT a valid class!
    // keep it as Object and cast it to XDesktop later (via queryInterface)
    Object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);
    XMultiServiceFactory xFactory = (XMultiServiceFactory) UnoRuntime.queryInterface(
        XMultiServiceFactory.class, xMCF);
    // what goes for desktop above is valid for DispatchHelper as well.
    Object dispatchHelper = xFactory.createInstance("com.sun.star.frame.DispatchHelper");

    // the DispatchHelper is the class that handles the interaction with dialogs.
    XDispatchHelper helper = (XDispatchHelper) UnoRuntime.queryInterface(
        XDispatchHelper.class, dispatchHelper);
    XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop);
    XFrame xFrame = xDesktop.getCurrentFrame();
    XDispatchProvider xDispatchProvider = (XDispatchProvider) UnoRuntime.queryInterface(XDispatchProvider.class, xFrame);

    // We issute the Track Changes Dialog (Bearbeiten - Änderungen // Edit - Changes) and tell it
    // to ACCEPT all changes.
    PropertyValue[] acceptChanges = new PropertyValue[1];
    acceptChanges[0] = new PropertyValue();
    acceptChanges[0].Name = "AcceptTrackedChanges";
    acceptChanges[0].Value = Boolean.TRUE;
    helper.executeDispatch(xDispatchProvider, ".uno:AcceptTrackedChanges", "", 0, acceptChanges);

    // We issue it again to tell it to stop showing changes.
    PropertyValue[] showChanges = new PropertyValue[1];
    showChanges[0] = new PropertyValue();
    showChanges[0].Name = "ShowTrackedChanges";
    showChanges[0].Value = Boolean.FALSE;
    helper.executeDispatch(xDispatchProvider, ".uno:ShowTrackedChanges", "", 0, showChanges);

我目前的猜测是我无法调用它,因为隐藏了,我没有Frame可以调用任何调度程序。但我找不到一种方法来获取Component的Dispatcher。

我已经尝试发送TrackChangesFALSE),但也没有这样做。

1 个答案:

答案 0 :(得分:4)

在花了两天时间了解OOo API之后,我意识到文档没有加载到前端,这就是为什么这种方法失败的原因。但是,您可以直接修改文档的属性:

XPropertySet docProperties = UnoRuntime.queryInterface(XPropertySet.class, document);
docProperties.setPropertyValue("RedlineDisplayType", RedlineDisplayType.NONE);

可以在RedlinePortion documentation

中找到属性名称"RedlineDisplayType"