当前,我们使用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/