gpt4 book ai didi

java - OpenOffice,将文档写入 servlet 响应

转载 作者:行者123 更新时间:2023-11-30 11:58:37 25 4
gpt4 key购买 nike

目前我们使用 OpenOffice 在模板文件文档中获取书签,并通过 Java 将它们替换为我们数据库中的内容。实际保存文件的代码行如下所示...

  XStorable storable = UnoRuntime.queryInterface(XStorable.class, document);


// Save as Word 97 Document
PropertyValue[] properties = new PropertyValue[1];
PropertyValue property = new PropertyValue();
property.Name = "FilterName";
property.Value = FORMAT_WORD_97;
properties[0] = property;
storable.storeAsURL(saveFileURL, properties);

我们想直接将文件写入 servlet 响应输出流,有没有人知道在 Java 中通过 OpenOffice 的 UNO api 直接将文档作为字节数组或输入流获取的方法?

最佳答案

这取决于 UNO API 的实现。我们能够用 PDF 做到这一点,

    OutputStream os = response.getOutputStream();

PropertyValue[] properties = new PropertyValue[2];
PropertyValue property = new PropertyValue();
property.Name = "FilterName";
property.Value = FORMAT_WORD_97;
properties[0] = property;
PropertyValue streamProp = new PropertyValue();
streamProp.Name = "OutputStream;
streamProp.Value = os;
properties[1] = streamProp;

storable.storeAsURL("private:stream", properties);

关于java - OpenOffice,将文档写入 servlet 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3097625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com