我的问题:我编写了一个自动化系统,该系统需要读取.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);

我目前的猜测是我不能调用此函数,因为它被隐藏了,没有框架可以调用任何调度程序。但是我找不到一种获取组件分派(dispatch)器的方法。

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

最佳答案

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

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

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

10-06 03:20