【问题标题】:OOo: UNO (Java) TrackedChanges: How to accept (or hide) Tracked Changes when Document is hidden?OOo:UNO(Java)TrackedChanges:隐藏文档时如何接受(或隐藏)跟踪更改?
【发布时间】:2012-02-28 17:26:51
【问题描述】:

我的问题:我编写了一个需要读取 .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),但也没成功。

【问题讨论】:

  • 你解决过这个问题吗?我希望加载选项可以做到这一点,但似乎也没有。
  • @FabianLange 不,我没有。但是GorgiKosev今天确实对此发表了答案。你会测试它吗?
  • 给这个人他的赏金!

标签: java openoffice.org dispatcher uno


【解决方案1】:

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

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

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

【讨论】:

  • Gorgi 出色的工作,完美运行。我不知道你在哪里找到那个文档,因为我自己找不到。但是这个简单的属性对我们有用!经过几天的寻找,我已经放弃了:)
  • @AngeloNeuschitzer 你测试了吗? :)
  • 这个问题在 9 年后得到了回答哇 @GorgiKosev 和 @AngeloFuchs 这应该是吉尼斯世界纪录吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-26
  • 1970-01-01
相关资源
最近更新 更多