Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ How to use Java to read OpenOffice document     - Installation Yarock 1.1.4 Music Player in Ubuntu (Linux)

- Linux find command detailing (Linux)

- Arduino UNO simulation development environment set up and run simulation (Linux)

- ASM learning overview (Database)

- To control based on IP address routing policy under Linux (Linux)

- Java to create a table in the database SYBase (Database)

- Android studio multi-channel ultra-compact version of the package (Programming)

- Ubuntu 12.04 / 14.04 users to install software LyX document processing (Linux)

- Linux + Apache + PHP + Oracle based environment to build (Server)

- How the program is executed (Programming)

- RedHat Linux 7 build yum source server (Server)

- How to create a secure and easy to remember password (Linux)

- Let the router be your security barrier against external attack (Linux)

- Use Epoll develop high-performance application server on Linux (Server)

- PL / SQL -> UTL_FILE use presentation package (Database)

- Oracle RMAN-06023 and ORA-19693 errors (Database)

- Linux Open coredump (Linux)

- Linux Routine Task Scheduler (Linux)

- Win8 mount disk partitions under Ubuntu (Linux)

- Python dictionary applications get built-in method (Programming)

  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.
- SQLite (Database)
- xCAT line installation on CentOS 6.X (Linux)
- Ubuntu user use PPA to install Uget 2.0.5 (Linux)
- Spring AOP (Programming)
- The correct way of logical backup mysqldump (Database)
- Getting Started with Linux system to learn: How do I know which processes are running on the CPU core (Linux)
- A new method for Linux hidden files (Linux)
- Ubuntu 14.04 Boot Repair (Linux)
- Elaborate .NET Multithreading: Using Task (Programming)
- Android thread mechanism --AsyncTask (Programming)
- CentOS 7.0 running Docker kernel error solution (Server)
- Ubuntu clean up unnecessary disk space usage (Linux)
- MongoDB query timeout exception SocketTimeoutException (Database)
- Fedora 23 How to install LAMP server (Server)
- MySQL query performance comparison of a single truth (Database)
- MySQL configuration file my.cnf increase the log file parameter error (Database)
- Linux program analysis tool: ldd and nm (Linux)
- Nine tips to protect the security of Linux desktop (Linux)
- Autojump: an advanced cd command in the Linux file system fast navigation (Linux)
- Unix system security configuration (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.