Apache Poi 简明教程

Apache POI - Overview

许多时候,一个软件应用程序需要生成 Microsoft Excel 文件格式的报告。有时,甚至希望一个应用程序接收 Excel 文件作为输入数据。例如,为公司财务部门开发的应用程序将需要以 Excel 形式输出所有输出。

Many a time, a software application is required to generate reports in Microsoft Excel file format. Sometimes, an application is even expected to receive Excel files as input data. For example, an application developed for the Finance department of a company will be required to generate all their outputs in Excel.

任何想要生成 MS Office 文件作为输出的 Java 编程人员都必须使用一个预定义且只读的 API 来执行此操作。

Any Java programmer who wants to produce MS Office files as output must use a predefined and read-only API to do so.

What is Apache POI?

Apache POI 是一个流行的 API,它允许编程人员使用 Java 程序创建、修改和显示 MS Office 文件。这是一个由 Apache Software Foundation 开发和分发的开放源代码库,用于使用 Java 程序设计或修改 Microsoft Office 文件。它包含类和方法,将用户输入数据或文件解码为 MS Office 文档。

Apache POI is a popular API that allows programmers to create, modify, and display MS Office files using Java programs. It is an open source library developed and distributed by Apache Software Foundation to design or modify Microsoft Office files using Java program. It contains classes and methods to decode the user input data or a file into MS Office documents.

Components of Apache POI

Apache POI 包含类和方法来处理 MS Office 的所有 OLE2 复合文档。这个 API 的组件列表如下。

Apache POI contains classes and methods to work on all OLE2 Compound documents of MS Office. The list of components of this API is given below.

  1. POIFS (Poor Obfuscation Implementation File System) − This component is the basic factor of all other POI elements. It is used to read different files explicitly.

  2. HSSF (Horrible Spreadsheet Format) − It is used to read and write xls format of MS-Excel files.

  3. XSSF (XML Spreadsheet Format) − It is used for xlsx file format of MS-Excel.

  4. HPSF (Horrible Property Set Format) − It is used to extract property sets of the MS-Office files.

  5. HWPF (Horrible Word Processor Format) − It is used to read and write doc extension files of MS-Word.

  6. XWPF (XML Word Processor Format) − It is used to read and write docx extension files of MS-Word.

  7. HSLF (Horrible Slide Layout Format) − It is used for read, create, and edit PowerPoint presentations.

  8. HDGF (Horrible DiaGram Format) − It contains classes and methods for MS-Visio binary files.

  9. HPBF (Horrible PuBlisher Format) − It is used to read and write MS-Publisher files.

本教程指导你完成使用 Java 处理 Excel 文件的流程。因此,讨论仅限于 HSSF 和 XSSF 组件。

This tutorial guides you through the process of working on Excel files using Java. Therefore the discussion is confined to HSSF and XSSF components.

Note − POI 的较早版本支持 doc、xls、ppt 等二进制文件格式。从版本 3.5 起,POI 开始支持 MS-Office 的 OOXML 文件格式,如 docx、xlsx、pptx 等。

Note − Older versions of POI support binary file formats such as doc, xls, ppt, etc. Version 3.5 onwards, POI supports OOXML file formats of MS-Office such as docx, xlsx, pptx, etc.

与 Apache POI 一样,还有其他供应商提供的其他 Excel 文件生成库。其中包括 Aspose 提供的 Aspose cells for Java ,Commons Libraries 提供的 JXL ,以及 Team Dev 提供的 JExcel

Like Apache POI, there are other libraries provided by various vendors for Excel file generation. These include Aspose cells for Java by Aspose, JXL by Commons Libraries, and JExcel by Team Dev.