Openoffice入门教程
首先安装
Apache_OpenOffice_4.0.1_Win_x86_install_zh-CN.exe 或者
Apache_OpenOffice_3.2.0_LinuxX86-_install_wJRE_zh-CN.tar.gz Linux 说明
1、复制Apache_OpenOffice_3.2.0_LinuxX86-_install_wJRE_zh-CN.tar.gz到/opt目录安装,安装命令如下:
tar -xzvf Apache_OpenOffice_3.2.0_LinuxX86-_install_wJRE_zh-CN.tar.gz
cd OOO320_m12_native_packed-1_zh-CN.9483/RPMS
rpm -ivh *.rpm
2、在/etc/rc.d/rc.local 中加入如下内容(假设openoffice安装在/opt/openoffice.org3):
/opt/openoffice.org3/program/soffice
\"-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager\" -nologo -headless -nofirststartwizard &
3、在shell命令窗口执行命令:nohup /opt/openoffice.org3/program/soffice -accept=\"socket,host=localhost,port=8100;urp;StarOffice.ServiceManager\" -nologo -headless -nofirststartwizard &
4、查看启动命令 ps -ef | grep openoffice
6、重启oa
Window说明
echo \"用以下命令启动OpenOffice服务\"
进入目录
cd C:\\Program Files (x86)\\OpenOffice 4\\program
输入启动服务
soffice -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard
Jar包说明 可以直接在当前word文档下载jar包
例子1
commons-io-1.4.jarjodconverter-2.2.0.jarjodconverter-cli-2.2.0.jarjuh-2.2.0.jarjurt-2.2.0.jarridl-2.2.0.jarslf4j-api-1.4.0.jarslf4j-jdk14-1.4.0.jarunoil-2.2.0.jarxstream-1.2.2.jar
例子2需要多家两个jar包
jooconverter-2.0rc2.jar
ridl-2.0.jar
例子1 package com.test; import java.io.File; import java.net.ConnectException; /** import net.sf.jooreports.converter.DocumentConverter; import net.sf.jooreports.converter.DocumentFormatRegistry; import net.sf.jooreports.converter.XmlDocumentFormatRegistry; import net.sf.jooreports.openoffice.connection.OpenOfficeConnection; import net.sf.jooreports.openoffice.connection.SocketOpenOfficeConnection; import net.sf.jooreports.openoffice.converter.OpenOfficeDocumentConverter; 注释掉的包用com.artofso*开头的包替换掉 **/ /** /** * OpenOfficeUtil * 将要转成的targetFile 带上后缀 * 工具本身能转成常用的html,pdf */ public class Test { public void docToPdf(File sourceFile, File targetFile){ //connect to an OpenOffice.org instance running on port 8100 DocumentFormatRegistry documentFormatRegistry = new XmlDocumentFormatRegistry(); //默认本机,如果是远程机器 new SocketOpenOfficeConnection(服务器IP地址,8100) OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); try{ connection.connect(); // convert DocumentConverter converter = new OpenOfficeDocumentConverter(connection , documentFormatRegistry); } converter.convert(sourceFile, targetFile); }catch(ConnectException cex){ cex.printStackTrace(); }finally{ // close the connection if(connection!=null){ connection.disconnect(); connection = null; } } } public static void main(String[] args) throws Exception{ Test p = new Test(); p.docToPdf(new File(\"d:\\\\XXX不受理告知书.doc\"),new File(\"d:\\\\aa.html\")); p.docToPdf(new File(\"d:\\\\XXX不受理告知书.doc\"),new File(\"d:\\\\aa.pdf\")); } 例子2 package com.test; import java.io.File; import java.net.ConnectException; import net.sf.jooreports.converter.DocumentConverter; import net.sf.jooreports.converter.DocumentFormatRegistry; import net.sf.jooreports.converter.XmlDocumentFormatRegistry; import net.sf.jooreports.openoffice.connection.OpenOfficeConnection; import net.sf.jooreports.openoffice.connection.SocketOpenOfficeConnection; import net.sf.jooreports.openoffice.converter.OpenOfficeDocumentConverter; /** /** * OpenOfficeUtil * 将要转成的targetFile 带上后缀 * 工具本身能转成常用的html,pdf */ public class Test { public void docToPdf(File sourceFile, File targetFile){ //connect to an OpenOffice.org instance running on port 8100 DocumentFormatRegistry documentFormatRegistry = new XmlDocumentFormatRegistry(); //默认本机,如果是远程机器 new SocketOpenOfficeConnection(服务器IP地址,8100) OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); try{ connection.connect(); // convert DocumentConverter converter = new OpenOfficeDocumentConverter(connection , documentFormatRegistry); converter.convert(sourceFile, targetFile); }catch(ConnectException cex){ cex.printStackTrace(); }finally{ // close the connection if(connection!=null){ connection.disconnect(); connection = null; } } } public static void main(String[] args) throws Exception{ Test p = new Test(); p.docToPdf(new File(\"d:\\\\XXX不受理告知书.doc\"),new File(\"d:\\\\aa.html\")); p.docToPdf(new File(\"d:\\\\XXX不受理告知书.doc\"),new File(\"d:\\\\aa.pdf\")); } }