Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ How to use Java to read OpenOffice document     - shell script: MySQL monitoring service is normal (Database)

- Install Unity 8 preview version of the desktop in Ubuntu (Linux)

- Intel Graphics Installer 1.0.3 released, support for Ubuntu (Linux)

- Ubuntu 12.04 installed OpenCV 2.3.1, binary image (Linux)

- Linux SVN installation and configuration graphic tutorials (Server)

- CentOS 7.0 Close firewall is enabled by default iptables firewall (Linux)

- Perl said method B if A judge (Programming)

- Go build the locale under Windows (Linux)

- To remove those IP is prohibited Fail2ban on CentOS 6/7 (Server)

- JEdit 5.2 Pro Edition installation on Ubuntu 14.04 (Linux)

- Linux system performance monitoring with Nmon (Linux)

- Linux Getting Started tutorial: Borrow Windows fonts in Ubuntu 14.10 (Linux)

- Service Discovery: Zookeeper vs etcd vs Consul (Server)

- Servlet life cycle code examples (Programming)

- Convert MySQL date string to a NULL value exception handling (Database)

- Use innobackupex full realization of MySQL hot backup (Database)

- Manage SQL Server services login (start) account and password (Database)

- CentOS 6 compiling httpd-2.4.10 (Server)

- How to install open source ITIL portal iTOP on CentOS 7 (Server)

- Raspberry Pi configuration wireless hotspot (Linux)

  How to use Java to read OpenOffice document
  Add Date : 2018-11-21      
  Due to the need of the project, we need to read the document in OpenOffice Java programs, and data processing. This article describes how to use the ODF Toolkit to read the contents of the OpenOffice SpreadSheet.

1. OpenOffice Spreedsheet document

The above documents are also included in the source code for this article.

OpenOffice document is actually stored in XML format that contains the document content and format control.

If you are using Unzip unzip tool, you will find that after decompression, a OpenOffice document actually contains the following elements
2. Download ODF4j

Odf4j is used to read OpenOffice documents (ODF) pure Java toolkit. At present, although not yet officially released, but already it has a deal with the basic functions of OpenOffice document.

Use Odf4j, Java programmers can easily create, modify OpenOffice documents.

3. Use ODF4j read OpenOffice document

Use ODF4j read OpenOffice document consists of two levels: Package Layer and Document Layer.

Package Layer

In the Package Layer, OpenOffice documents in a variety of resources as a named resource to deal with. Usually at this level for operating binary files, such as pictures.

Document Layer

In the Document Layer, is on the main content of the document operation. At this level, the content of the document is to be operated as a hierarchy, because the content of the document is saved in an XML file mode, it can be very easy to DOM approach to the operation. The following example will read a Document Layer OpenOffice Spreadsheet document.

4. Read the document OpenOffice Spreadsheet

import org.openoffice.odf.OdfPackage;

import org.openoffice.odf.OpenDocumentFactory;

import org.openoffice.odf.spreadsheet.SpreadsheetDocument;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;


OdfPackage odfPackage;

odfPackage = (SpreadsheetDocument) OpenDocumentFactory.load (path);

Document doc = odfPackage.getDocument (OdfPackage.STREAMNAME_CONTENT);

Element root = doc.getDocumentElement ();


Source code

After obtaining root Element, we can read the image reading xml files as OpenOffice document content.
5. The result of the program

Download the article source into the root directory NetBean Project, and then run: ant run. Operating results
References: Element

1. ODF4j: http://wiki.services.openoffice.org/wiki/Odf4j

2. Source code for this article.
- How do I upgrade from Ubuntu 15.04 to Ubuntu 15.10 (Linux)
- 14 useful example Linux Sort command (Linux)
- Build ftp server under CentOS 6.5 (Server)
- Tip: Use Cryptsetup U disk encryption (Linux)
- Depth study and understanding for individual users suicide DDoS attacks (Linux)
- Multipath configuration under Linux (Linux)
- Android project using the command to create and install the package (Programming)
- Supervisor Installation and Configuration (Server)
- Zabbix configuration external network mail alarm (Server)
- Tune in high resolution to 1280x800 in Fedora 14 (Linux)
- Oracle physical storage structure outline (Database)
- Configuring Allatori code confusion when developing general Java applications in NetBeans (Programming)
- Ubuntu 14.04 How to set up an SSH without password (Linux)
- Linux file time Comments ctime mtime atime (Linux)
- CV: Linux command displays the progress of the run command (Linux)
- Java Concurrency -volatile keywords (Programming)
- Lua4.0 interpreter documents (Programming)
- Ubuntu Live CD by updating Grub resume boot the Boot Menu (Linux)
- Linux network monitoring tools ntopng installation (Linux)
- By creating a personal technology blog Detailed GitHub (Linux)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.