5

我的问题:我编写了一个需要读取 .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);

我目前的猜测是我不能调用它,因为被隐藏了,我没有框架可以调用任何调度程序。但是我找不到获取组件的调度程序的方法。

我也已经尝试过发送TrackChanges(到FALSE),但也没有这样做。

4

1 回答 1

4

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

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

属性名称"RedlineDisplayType"可以在RedlinePortion 文档中找到

于 2014-02-21T17:26:08.480 回答