openoffice安装

Posted Redheat

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了openoffice安装相关的知识,希望对你有一定的参考价值。

openoffice可以在Linux上完成office文件转为pdf文件

安装x window    
  105  yum groupinstall "X Window System"
    2   yum -y install lrzsz ntp bash rsync pciutils dmidecode wget bind-utils  openssh-clients   lftp  telnet gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts
    8  cd /usr/local/src/
安装openoffice
   14  tar xvf Apache_OpenOffice_4.1.3_Linux_x86-64_install-rpm_zh-CN.tar.gz 
   15  cd zh-CN/
   16  cd RPMS/
   18  rpm -ivh *
   19  rpm -ivh *.rpm
安装SDK
   22  tar xvf Apache_OpenOffice-SDK_4.1.3_Linux_x86-64_install-rpm_en-US.tar.gz 
   23  cd en-US/
   24  cd RPMS/
   25  rpm -ivh openoffice-sdk-4.1.3-9783.x86_64.rpm 
安装easy_install
   28  wget -q http://peak.telecommunity.com/dist/ez_setup.py
   30  python ez_setup.py 
安装pip
   31  wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
   32  tar xvf pip-9.0.1.tar.gz 
   33  cd pip-9.0.1
   34  python setup.py install
安装uno
   35  pip install uno
配置系统服务
   37  vim /etc/init.d/soffice
#!/bin/bash  
# Boot open office so that Alfresco can do transforms.  
# chkconfig: 2345 55 25  
# description: OpenOffice Headless  
#  
# processname: soffice  
# source function library  
. /etc/rc.d/init.d/functions
RETVAL=0
VDISPLAY=99
SOFFICE_PATH=/opt/openoffice4/program
SOFFICE_ARGS1="-nofirststartwizard -nologo -headless -display :$VDISPLAY "
SOFFICE_ARGS2=-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager
SOFFICE_PIDFILE=/var/run/soffice.pid
start_soffice() {
       echo -n $"Starting OpenOffice"  
       $SOFFICE_PATH/soffice $SOFFICE_ARGS1 $SOFFICE_ARGS2 >/dev/null 2>&1 &
       [ $? -eq 0 ] && echo_success || echo_failure
       pidof soffice > $SOFFICE_PIDFILE
       echo  
}
start() {
       start_soffice
}
stop() {
       echo -n $"Stopping OpenOffice"  
       killproc soffice
       echo  
}
case "$1" in
       start)
               start
               ;;
       stop)
               stop
               ;;
       restart)
               stop
               start
               ;;
       *)
               echo $"Usage: $0 {start|stop|restart}"  
esac

   38  chmod 755 /etc/init.d/soffice
安装桌面图形
   80  rpm -ivh openoffice4.1.3-redhat-menus-4.1.3-9783.noarch.rpm 
安装vim和ifconfig
   90  yum install vim *
   91  yum install net-tools.x86_64
安装java
  121  tar xvf jdk-8u65-linux-x64.tar.gz 
  128  cp -r jdk1.8.0_65 /opt/java
  131  vim /etc/profile
export JAVA_HOME=/opt/java/
export JRE_HOME=/opt/java/jre
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
  132  source /etc/profile
  136  java -version
启动服务
   39  /etc/init.d/soffice start
修改 DocumentConverter.py端口
  178  vim DocumentConverter.py 
安装中文支持
  223  yum install kde-l10n-Chinese
上传Windows字体到linux
  335  unzip Fonts.zip 
  338  cd /usr/share/fonts/
  339  ln -s /data0/Fonts win7fonts
  340  cd win7fonts/
  343  yum install mkfontscale
  344  mkfontscale
  345  mkfontdir
  346  fc-cache
重启
  354  reboot 
  356  cd /usr/share/fonts/
  359  cd win7fonts/
  361  fc-cache
  362  /etc/init.d/soffice start
  363  cd /data0/pdf/
  366  /opt/openoffice4/program/python DocumentConverter.py a.xlsx 1.pdf
 
DocumentConverter.py


# #
PyODConverter (Python OpenDocument Converter) v1.1 - 2009-11-14 # # This script converts a document from one office format to another by # connecting to an OpenOffice.org instance via Python-UNO bridge. # # Copyright (C) 2008-2009 Mirko Nasato <[email protected]> # Licensed under the GNU LGPL v2.1 - http://www.gnu.org/licenses/lgpl-2.1.html # - or any later version. # DEFAULT_OPENOFFICE_PORT = 8100 import uno from os.path import abspath, isfile, splitext from com.sun.star.beans import PropertyValue from com.sun.star.task import ErrorCodeIOException from com.sun.star.connection import NoConnectException FAMILY_TEXT = "Text" FAMILY_WEB = "Web" FAMILY_SPREADSHEET = "Spreadsheet" FAMILY_PRESENTATION = "Presentation" FAMILY_DRAWING = "Drawing" #---------------------# # Configuration Start # #---------------------# # see http://wiki.services.openoffice.org/wiki/Framework/Article/Filter # most formats are auto-detected; only those requiring options are defined here IMPORT_FILTER_MAP = { "txt": { "FilterName": "Text (encoded)", "FilterOptions": "utf8" }, "csv": { "FilterName": "Text - txt - csv (StarCalc)", "FilterOptions": "44,34,0" } } EXPORT_FILTER_MAP = { "pdf": { FAMILY_TEXT: { "FilterName": "writer_pdf_Export" }, FAMILY_WEB: { "FilterName": "writer_web_pdf_Export" }, FAMILY_SPREADSHEET: { "FilterName": "calc_pdf_Export" }, FAMILY_PRESENTATION: { "FilterName": "impress_pdf_Export" }, FAMILY_DRAWING: { "FilterName": "draw_pdf_Export" } }, "html": { FAMILY_TEXT: { "FilterName": "HTML (StarWriter)" }, FAMILY_SPREADSHEET: { "FilterName": "HTML (StarCalc)" }, FAMILY_PRESENTATION: { "FilterName": "impress_html_Export" } }, "odt": { FAMILY_TEXT: { "FilterName": "writer8" }, FAMILY_WEB: { "FilterName": "writerweb8_writer" } }, "doc": { FAMILY_TEXT: { "FilterName": "MS Word 97" } }, "rtf": { FAMILY_TEXT: { "FilterName": "Rich Text Format" } }, "txt": { FAMILY_TEXT: { "FilterName": "Text", "FilterOptions": "utf8" } }, "ods": { FAMILY_SPREADSHEET: { "FilterName": "calc8" } }, "xls": { FAMILY_SPREADSHEET: { "FilterName": "MS Excel 97" } }, "csv": { FAMILY_SPREADSHEET: { "FilterName": "Text - txt - csv (StarCalc)", "FilterOptions": "44,34,0" } }, "odp": { FAMILY_PRESENTATION: { "FilterName": "impress8" } }, "ppt": { FAMILY_PRESENTATION: { "FilterName": "MS PowerPoint 97" } }, "swf": { FAMILY_DRAWING: { "FilterName": "draw_flash_Export" }, FAMILY_PRESENTATION: { "FilterName": "impress_flash_Export" } } } PAGE_STYLE_OVERRIDE_PROPERTIES = { FAMILY_SPREADSHEET: { #--- Scale options: uncomment 1 of the 3 --- # a) ‘Reduce / enlarge printout‘: ‘Scaling factor‘ "PageScale": 100, # b) ‘Fit print range(s) to width / height‘: ‘Width in pages‘ and ‘Height in pages‘ #"ScaleToPagesX": 1, "ScaleToPagesY": 1000, # c) ‘Fit print range(s) on number of pages‘: ‘Fit print range(s) on number of pages‘ #"ScaleToPages": 1, "PrintGrid": False } } #-------------------# # Configuration End # #-------------------# class DocumentConversionException(Exception): def __init__(self, message): self.message = message def __str__(self): return self.message class DocumentConverter: def __init__(self, port=DEFAULT_OPENOFFICE_PORT): localContext = uno.getComponentContext() resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext) try: context = resolver.resolve("uno:socket,host=localhost,port=%s;urp;StarOffice.ComponentContext" % port) except NoConnectException: raise DocumentConversionException, "failed to connect to OpenOffice.org on port %s" % port self.desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context) def convert(self, inputFile, outputFile): inputUrl = self._toFileUrl(inputFile) outputUrl = self._toFileUrl(outputFile) loadProperties = { "Hidden": True } inputExt = self._getFileExt(inputFile) if IMPORT_FILTER_MAP.has_key(inputExt): loadProperties.update(IMPORT_FILTER_MAP[inputExt]) document = self.desktop.loadComponentFromURL(inputUrl, "_blank", 0, self._toProperties(loadProperties)) try: document.refresh() except AttributeError: pass family = self._detectFamily(document) self._overridePageStyleProperties(document, family) outputExt = self._getFileExt(outputFile) storeProperties = self._getStoreProperties(document, outputExt) try: document.storeToURL(outputUrl, self._toProperties(storeProperties)) finally: document.close(True) def _overridePageStyleProperties(self, document, family): if PAGE_STYLE_OVERRIDE_PROPERTIES.has_key(family): properties = PAGE_STYLE_OVERRIDE_PROPERTIES[family] pageStyles = document.getStyleFamilies().getByName(PageStyles) for styleName in pageStyles.getElementNames(): pageStyle = pageStyles.getByName(styleName) for name, value in properties.items(): pageStyle.setPropertyValue(name, value) def _getStoreProperties(self, document, outputExt): family = self._detectFamily(document) try: propertiesByFamily = EXPORT_FILTER_MAP[outputExt] except KeyError: raise DocumentConversionException, "unknown output format: ‘%s‘" % outputExt try: return propertiesByFamily[family] except KeyError: raise DocumentConversionException, "unsupported conversion: from ‘%s‘ to ‘%s‘" % (family, outputExt) def _detectFamily(self, document): if document.supportsService("com.sun.star.text.WebDocument"): return FAMILY_WEB if document.supportsService("com.sun.star.text.GenericTextDocument"): # must be TextDocument or GlobalDocument return FAMILY_TEXT if document.supportsService("com.sun.star.sheet.SpreadsheetDocument"): return FAMILY_SPREADSHEET if document.supportsService("com.sun.star.presentation.PresentationDocument"): return FAMILY_PRESENTATION if document.supportsService("com.sun.star.drawing.DrawingDocument"): return FAMILY_DRAWING raise DocumentConversionException, "unknown document family: %s" % document def _getFileExt(self, path): ext = splitext(path)[1] if ext is not None: return ext[1:].lower() def _toFileUrl(self, path): return uno.systemPathToFileUrl(abspath(path)) def _toProperties(self, dict): props = [] for key in dict: prop = PropertyValue() prop.Name = key prop.Value = dict[key] props.append(prop) return tuple(props) if __name__ == "__main__": from sys import argv, exit if len(argv) < 3: print "USAGE: python %s <input-file> <output-file>" % argv[0] exit(255) if not isfile(argv[1]): print "no such input file: %s" % argv[1] exit(1) try: converter = DocumentConverter() converter.convert(argv[1], argv[2]) except DocumentConversionException, exception: print "ERROR! " + str(exception) exit(1) except ErrorCodeIOException, exception: print "ERROR! ErrorCodeIOException %d" % exception.ErrCode exit(1)

 

以上是关于openoffice安装的主要内容,如果未能解决你的问题,请参考以下文章

将 Java UNO 代码从 OpenOffice 2.4 迁移到 3.0

为了让 OpenOffice.org Calc 读取 Excel 文件中的 VBA 代码,我需要做啥?

安装OpenOffice

基于openOffice和python实现office转pdf和html示例代码

openoffice安装

CentOS-7 安装OpenOffice