Apache Poi Ppt 简明教程
Apache POI PPT - Installation
本教程将指导你完成在 Windows 和 Linux 系统上设置 Apache POI 的流程。Apache POI 可以在不执行任何复杂设置程序的情况下,使用几个简单的步骤轻松安装并集成到当前的 Java 环境中。在安装时需要有用户管理权限。
This chapter takes you through the process of setting up Apache POI on Windows and Linux based systems. Apache POI can be easily installed and integrated with your current Java environment following a few simple steps without any complex setup procedures. User administration is required while installation.
System Requirements
JDK |
Java SE 2 JDK 1.5 or above |
Memory |
1 GB RAM (recommended) |
Disk Space |
No minimum requirement |
Operating System Version |
Windows XP or above, Linux |
现在让我们继续进行安装 Apache POI 的步骤。
Let us now proceed with the steps to install Apache POI.
Step 1 − Verify your Java Installation
首先,你的系统中需要安装 Java 软件开发工具包 (SDK)。要验证这一点,请根据所使用的平台执行以下两个命令。
First of all, you need to have Java Software Development Kit (SDK) installed on your system. To verify this, execute any of the two commands depending on the platform you are working on.
如果 Java 安装已正确完成,则它将显示 Java 安装的当前版本和规范。以下表中给出了一个示例输出。
If the Java installation has been done properly, then it will display the current version and specification of your Java installation. A sample output is given in the following table.
Platform |
Command |
Sample Output |
Windows |
Open command console and type − >java –version |
java version "11.0.11" 2021-04-20 LTS Open JDK Runtime Environment 18.9 (build 11.0.11+9-LTS-194) Open JDK 64-Bit Server VM (build 11.0.11+9-LTS-194, mixed mode) |
Linux |
Open command terminal and type − $java –version |
java version "11.0.11" 2021-04-20 LTS Open JDK Runtime Environment 18.9 (build 11.0.11+9-LTS-194) Open JDK 64-Bit Server VM (build 11.0.11+9-LTS-194, mixed mode) |
-
We assume the readers of this tutorial have Java SDK version 11.0.11 installed on their system.
-
In case you do not have Java SDK, download its current version from www.oracle.com/technetwork/java/javase/downloads/index.html and have it installed.
Step 2 − Set your Java Environment
设置环境变量 JAVA_HOME 以指向计算机上安装 Java 的基本目录位置。例如,
Set the environment variable JAVA_HOME to point to the base directory location where Java is installed on your machine. For example,
Sr.No. |
Platform & Description |
1 |
Windows Set JAVA_HOME to C:\ProgramFiles\java\jdk11.0.11 |
2 |
Linux Export JAVA_HOME = /usr/local/java-current |
将 Java 编译器位置的完整路径附加到系统路径。
Append the full path of Java compiler location to the System Path.
Sr.No. |
Platform & Description |
1 |
Windows Append the String "C:\Program Files\Java\jdk11.0.11\bin" to the end of the system variable PATH. |
2 |
Linux Export PATH = $PATH:$JAVA_HOME/bin/ |
如上所述,从命令提示符执行命令 java -version 。
Execute the command java -version from the command prompt as explained above.
Step 3 − Install Apache POI Library
从 https://poi.apache.org/download.html 下载最新版本的 Apache POI,并将其内容解压缩到一个文件夹中,然后可以将该文件夹中的所需库连接到你的 Java 程序。我们假设这些文件保存在 C 驱动器的文件夹中。
Download the latest version of Apache POI from https://poi.apache.org/download.html and unzip its contents to a folder from where the required libraries can be linked to your Java program. Let us assume the files are collected in a folder on C drive.
将必需的 jars 的完整路径添加到 CLASSPATH,如下所示。
Add the complete path of the required jars as shown below to the CLASSPATH.
Sr.No. |
Platform & Description |
1 |
Windows Append the following strings to the end of the user variable CLASSPATH − C:\poi-bin-5.1.0\poi-5.1.0.jar; C:\poi-bin-5.1.0\poi-ooxml-5.1.0.jar; C:\poi-bin-5.1.0\poi-ooxml-full-5.1.0.jar; C:\poi-bin-5.1.0\lib\commons-codec-1.15.jar; C:\poi-bin-5.1.0\lib\commons-collections4-4.4.jar; C:\poi-bin-5.1.0\lib\commons-io-2.11.0.jar; C:\poi-bin-5.1.0\lib\commons-math3-3.6.1.jar; C:\poi-bin-5.1.0\lib\log4j-api-2.14.1.jar; C:\poi-bin-5.1.0\lib\SparseBitSet-1.2.jar; C\poi-bin-5.1.0\ooxml-lib\commons-compress-1.21.jar C\poi-bin-5.1.0\ooxml-lib\commons-logging-1.2.jar C\poi-bin-5.1.0\ooxml-lib\curvesapi-1.06.jar C\poi-bin-5.1.0\ooxml-lib\slf4j-api-1.7.32.jar C\poi-bin-5.1.0\ooxml-lib\xmlbeans-5.0.2.jar |
2 |
Linux Export CLASSPATH = $CLASSPATH: /usr/share/poi-bin-5.1.0/poi-5.1.0.jar.tar: /usr/share/poi-bin-5.1.0/poi-ooxml-5.1.0.tar: /usr/share/poi-bin-5.1.0/poi-ooxml-full-5.1.0.tar: /usr/share/poi-bin-5.1.0/lib/commons-codec-1.15.jar.tar: /usr/share/poi-bin-5.1.0/lib/commons-collections4-4.4.tar: /usr/share/poi-bin-5.1.0/lib/commons-io-2.11.0.tar: /usr/share/poi-bin-5.1.0/lib/commons-math3-3.6.1.tar: /usr/share/poi-bin-5.1.0/lib/log4j-api-2.14.1.tar: /usr/share/poi-bin-5.1.0/lib/SparseBitSet-1.2.tar: /usr/share/poi-bin-5.1.0/ooxml-lib/commons-compress-1.21.tar: /usr/share/poi-bin-5.1.0/ooxml-lib/commons-logging-1.2.tar: /usr/share/poi-bin-5.1.0/ooxml-lib/curvesapi-1.06.tar: /usr/share/poi-bin-5.1.0/ooxml-lib/slf4j-api-1.7.32.tar: /usr/share/poi-bin-5.1.0/ooxml-lib/xmlbeans-5.0.2.tar: |
pom.xml
以下是运行本教程中程序的 pom.xml 文件。
Following is the pom.xml file to run the programs in this tutorial.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ApachePoiPPT</groupId>
<artifactId>ApachePoiPPT</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
<compilerArgs>
<arg>--add-modules</arg>
<arg>java.se,java.desktop</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.1.0</version>
</dependency>
</dependencies>
</project>