Tag: openoffice.org

通过Java连接到OpenOffice时,没有办公室可执行文件发现exception

使用XComponentContext xContext = Bootstrap.bootstrap() ,我试图通过Java获取OpenOffice的远程办公组件上下文。但是它引发了exception, no office executable found 。 我已经在CLASSPATH中指定了OpenOffice程序目录的路径,但是我得到了这个exception。如何解决这个问题?

如何使用java将图像插入到openoffice编写器文档中?

我正在尝试从模板创建一个openoffice编写器文档。 我可以用这段代码替换报告的文本部分 private static void searchAndReplace(final String search, final String replace, final XTextDocument mxDoc) { XReplaceable xReplaceable = (XReplaceable) UnoRuntime.queryInterface( XReplaceable.class, mxDoc); XReplaceDescriptor xRepDesc = xReplaceable.createReplaceDescriptor(); xRepDesc.setSearchString(search); xRepDesc.setReplaceString(replace); xReplaceable.replaceAll(xRepDesc); } 我从这里找到了一些示例代码,用于将图像链接或嵌入到xTextDocument中。 但是,我无法插入到xTextDocument中。 有没有其他方法可以用Java做到这一点? Openoffice版本是3.1.0。 有答案吗?

从Java启动OpenOffice服务(soffice)的问题(命令行中的命令,但不是Java)

我想要一个简单的命令,它可以从shell运行,但不能用Java运行。 这是我想要执行的命令,工作正常: soffice -headless “-accept=socket,host=localhost,port=8100;urp;” 这是我试图运行此命令从Java中获取的代码: String[] commands = new String[] {“soffice”,”-headless”,”\”-accept=socket,host=localhost,port=8100;urp;\””}; Process process = Runtime.getRuntime().exec(commands) int code = process.waitFor(); if(code == 0) System.out.println(“Commands executed successfully”); 当我运行这个程序时,我得到“命令执行成功”。 但是,当程序完成时,该过程不会运行。 JVM运行后是否有可能杀死程序? 为什么这不起作用?

合并代码中的两个.odt文件

你如何合并两个.odt文件? 手动执行此操作,打开每个文件并复制内容都可行,但不可行。 我尝试过odttoolkit Simple API(simple-odf-0.8.1-incubating)来实现这个任务,创建一个空的TextDocument并将所有内容合并到其中: private File masterFile = new File(…); … TextDocument t = TextDocument.newTextDocument(); t.save(masterFile); … for(File f : filesToMerge){ joinOdt(f); } … void joinOdt(File joinee){ TextDocument master = (TextDocument) TextDocument.loadDocument(masterFile); TextDocument slave = (TextDocument) TextDocument.loadDocument(joinee); master.insertContentFromDocumentAfter(slave, master.getParagraphByReverseIndex(0, false), true); master.save(masterFile); } 这样做效果相当不错,但它丢失了有关字体的信息 – 原始文件是Arial Narrow和Windings(用于复选框)的组合,输出masterFile都在TimesNewRoman中。 起初我怀疑insertContentFromDocumentAfter的最后一个参数,但是将其更改为false会中断(几乎)所有格式化。 难道我做错了什么? 还有别的办法吗?

excel(.xlsx)使用开放式办公室转换为pdf(.pdf)时缺少工作表和页面大小问题

我使用JodConverter和Open-Office创建了一个应用程序,用于将excel( .xlsx )转换为PDF ,该应用程序运行正常,但我遇到了两个问题 输出PDF的页面是A4大小的forms,因为某些工作表内容已被切掉。 因为我希望excel的每个工作表都像在一个页面中一样完整。 缺少工作表,如果我的excel有8个工作表,我在PDF输出中只得到两个或三个 即使我们试图直接从开放办公室转换为pdf ,它也会给出上述类似的问题 Excel文件 – ss1.xlsx 输出PDF – work.pdf 任何人都可以告诉我一些解决方案 我的代码如下所示 public class MyConverter { public static void main(String[] args) throws ConnectException { File inputFile = new File(“C:/Users/Work/Desktop/ss1.xlsx”); File outputFile = new File(“C:/Users/Work/Desktop/work.pdf”); // connect to an OpenOffice.org instance running on port 8100 OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); connection.connect(); […]

如何使用UNO获取打开的文档?

我正在编写一个打开对话框的附加组件,我需要访问当前打开的文本文档,但我不知道如何获取它。 我在NetBeans中使用OpenOffice插件,我从一个Add-on项目开始。 它创建了一个类,它给了我一个XComponentContext实例,但我不知道如何使用它来获取当前文档的OfficeDocument实例。 我已经谷歌搜索了一段时间,我找不到任何使用现有的,打开的文档的例子。 它们都是从一个新文档或首先加载的文档开始的,因此它们有一个URL。 我根据OpenOffice wiki( https://wiki.openoffice.org/wiki/API/Samples/Java/Office/DocumentHandling )试了一下,这就是我想出的: private OfficeDocument getDocument() { if (this.officeDocument == null) { try { // this causes the error XMultiComponentFactory xMultiComponentFactory = this.xComponentContext.getServiceManager(); Object oDesktop = xMultiComponentFactory.createInstanceWithContext(“com.sun.star.frame.Desktop”, this.xComponentContext); XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, oDesktop); String url = “private:factory/swriter”; String targetFrameName = “_self”; int searchFlags = FrameSearchFlag.SELF; PropertyValue[] propertyValues = new […]

OpenOffice使用JAVA将doc转换为pdf

我知道它有很多问题。 但我已经阅读了大量的内容,它仍然无法正常工作。 我已将OpenOffice安装到我的comp: https : //www.openoffice.org/download/index.html 我也试过这个解决方案,不起作用: 连接到OpenOffice .org时连接失败 如果我想运行我的代码,我会收到以下错误: Exception in thread “main” java.net.ConnectException: connection failed: socket,host=localhost,port=8100,tcpNoDelay=1: java.net.ConnectException: Connection refused: connect at com.artofsolving.jodconverter.openoffice.connection.AbstractOpenOfficeConnection.connect(AbstractOpenOfficeConnection.java:79) at TestCon.main(TestCon.java:24 ) 如何管理连接到我的openoffice程序。 PS:我想在Windows 7 64x上使用它 我用这个简单的代码 import java.io.File; import java.net.ConnectException; import com.artofsolving.jodconverter.DocumentConverter; import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection; import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter; public class TestCon { /** * @param args * @throws ConnectException […]

在Java中使用Office文档创建PDF的好方法

我正在寻找一种将Office(主要是Microsoft)文档转换为Java的PDF的好方法。 我一直在考虑使用OpenOffice SDK,但从我看过的样本看来,这需要让OpenOffice在服务器模式下运行才能完成工作。 有谁知道这样做的好方法? 好的意思是外部要求越少越好。 100%的Java API是最好的,但我不认为它确实存在。

如何用java以编程方式创建odt文件?

如何以编程方式使用Java创建odt(LibreOffice / OpenOffice Writer)文件? 一个“你好世界”的例子就足够了。 我查看了OpenOffice网站,但文档不清楚。

如何在服务器模式下将OpenOffice用作multithreading服务?

在服务器模式下使用OpenOffice有什么经验? 我知道OpenOffice不是multithreading的,现在我需要在我们的服务器中使用它的服务。 我该怎么做才能克服这个问题? 我正在使用Java。