Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ How to use Java to read OpenOffice document     - Linux user login and IP restrictions (Linux)

- Production Environment MongoDB Fragmentation and Cluster Solution (Database)

- Setting up Linux machine through a proxy firewall (Linux)

- Ora-14450: attempt to access ah transactional temptable already in use (Database)

- Android engineers interview questions (Programming)

- C language files update in real time (Programming)

- Ubuntu and Archlinux install Notepadqq 0.50.2 (Linux)

- Linux Getting Started tutorial: Experience KVM Virtual Machine chapter (Linux)

- How to configure MongoDB replica set (Database)

- ORA-12154: TNS: could not resolve the connect identifier specified solve (Database)

- error 1819 (HY000): your password does not satisfy the current policy requirements (Database)

- Unix / Linux commonly used to clean up disk space command (Linux)

- MySQL service failed to start thinking of settlement under CentOS7 (Database)

- Linux operating system ARP Spoofing Defense (Linux)

- TPCC-MySQL Benchmark (Database)

- Open log in Hibernate (Programming)

- Java polymorphism and exception handling (Programming)

- Use Tails 1.4 Linux system to protect the privacy and anonymity (Linux)

- The user of fedora is not in the sudoers file method to solve (Linux)

- Linux system firewall defense network attacks (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.
- Linux system security knowledge (Linux)
- After you change the GRUB boot disk partition repair (Linux)
- To install PXE + Kickstart under CentOS 6.x operating system (Linux)
- Linux directory permissions to read and execute permissions difference (Linux)
- CentOS Linux build SVN server (Server)
- React Native (Programming)
- Ubuntu Series Installation Docker (Linux)
- Linux System Tutorial: Ubuntu on the desktop is disabled by default keyring to unlock tips (Linux)
- Adjustment expand VMDK format VirtualBox disk space (Linux)
- Performance comparison Fibonacci recursive and non-recursive (Programming)
- How to fix Ubuntu / Mint can not add PPA source of error (Linux)
- PostgreSQL Stream Configuration (Database)
- How to enable fbcon in Debian (Linux)
- Lua4.0 interpreter documents (Programming)
- Redis configuration file interpretation (Database)
- How to set the default Fedora from the command line (Linux)
- ORA-12154: TNS: could not resolve the connect identifier specified solve (Database)
- Ubuntu installation under Scrapy (Linux)
- Linux Systemd-- To start / stop / restart services in RHEL / CentOS 7 (Linux)
- Linux foreground to background process switch (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.