Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ How to use Java to read OpenOffice document     - Use smartmontools view the health status of hard disk (Linux)

- CentOS install SVN server configuration and automatically synchronized to the Web directory (Server)

- Why do I prefer Git (Linux)

- C ++ string in the end (Programming)

- The basic principles for the protection of a good linux server security (Linux)

- Ubuntu / Fedora / CentOS system how to install Plex Media Server 0.9.9 (Linux)

- php How to prevent being injected (Linux)

- Create a DLL using MinGW and Attention (Programming)

- Node.JS different ways to install under Ubuntu 15.04 (Linux)

- Linux folder and extract the differential file comparison techniques -rsync Magical (Linux)

- Linux server startup and logon security settings (Linux)

- How Vim playing a mature IDE (Linux)

- MySQL binlog automatic cleanup script (Database)

- Java static internal class (Programming)

- RHEL5 establish a local yum source (Linux)

- Configuring Haproxy log support (syslog logging support) (Server)

- To learn from scratch OpenWrt perfect tutorial (Linux)

- dmidecode command Detailed (Hardware information) (Linux)

- Embedded Linux to solve the problem in the time zone (Linux)

- How to disable IPv6 on Ubuntu, Linux Mint, Debian (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.
- MySQL configuration file my.cnf increase the log file parameter error (Database)
- Oracle 11g modify MEMORY_TARGET (Database)
- Linux system installation Gitlab (Server)
- MariaDB database storage path modify configuration issues (Database)
- Linux System Tutorial: Ubuntu on the desktop is disabled by default keyring to unlock tips (Linux)
- Nginx is used to build the cache module srcache_nginx (Server)
- Use innobackupex full realization of MySQL hot backup (Database)
- Add local search to your Android app (Programming)
- JBPM6 Tutorial - Fast Fun JBPM table (Linux)
- rpm package specify the installation path (Linux)
- Linux System Getting Started Learning: compile and install ixgbe driver in Ubuntu or Debian (Linux)
- Use IF NOT EXISTS create a data table (Database)
- Multipath configuration under Linux (Linux)
- Source code to compile and install MySQL 5.7.9 (Database)
- Android Qemu GPS module (Programming)
- Android in the event delivery and handling mechanism (Programming)
- Linux command execution judge sentences -;, &&, || (Linux)
- CentOS set up FTP server (Server)
- Ubuntu program using the Sound Recorder (Linux)
- Linux Hard Disk Partition and file system management (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.