简体   繁体   English

如何将 apache poi 添加到 java?

[英]How to add apache poi to java?

I am a beginner in java.我是java初学者。 I have downloaded a latest version of apache poi 3.16.我已经下载了最新版本的 apache poi 3.16。
There are several jar files renamed and edited from old versions.有几个 jar 文件从旧版本重命名和编辑。 i want to know how to set class path for the files in steps and what are all the jar files that need class path?我想知道如何分步设置文件的类路径以及需要类路径的所有 jar 文件是什么? I have imported all the jar files but it showed class not found exception in this code.我已经导入了所有的 jar 文件,但它在此代码中显示未找到类异常。

import java.io.*;
import org.apache.poi.xssf.usermodel.*;
public class CreateWorkBook 
{
   public static void main(String[] args)throws Exception 
   {
      //Create Blank workbook
      XSSFWorkbook workbook = new XSSFWorkbook(); 
      //Create file system using specific name
      FileOutputStream out = new FileOutputStream(
      new File("createworkbook.xlsx"));
      //write operation workbook using file out object 
      workbook.write(out);
      out.close();
      System.out.println("
      createworkbook.xlsx written successfully");
   }
}

Before setting the classpath for the jars create a lib folder with in your project folder and copy all the jar files in this folder.在为 jars 设置类路径之前,在您的项目文件夹中创建一个 lib 文件夹,并复制该文件夹中的所有 jar 文件。 For example:例如:

D:\\Project\\Java\\lib D:\\Project\\Java\\lib

After that include this location in your path.之后,将此位置包含在您的路径中。

For setting the path and classpath you can check this link:要设置路径和类路径,您可以查看此链接:

https://docs.oracle.com/javase/tutorial/essential/environment/paths.html https://docs.oracle.com/javase/tutorial/essential/environment/paths.html

For setting the path following steps:设置路径步骤如下:

Go to system properties进入系统属性

Click on advanced system settings点击高级系统设置

Click on environment variables点击环境变量

If using Eclipse, follow https://stackoverflow.com/a/3280384/3940047 for instructions.如果使用 Eclipse,请按照https://stackoverflow.com/a/3280384/3940047获取说明。 This library has other dependencies that need to be imported - ensure you've done that.这个库还有其他需要导入的依赖项——确保你已经这样做了。

com.github.virtuald » curvesapi com.github.virtuald » 曲线 API

org.apache.poi » poi org.apache.poi » poi

org.apache.poi » poi-ooxml-schemas org.apache.poi » poi-ooxml-schemas

If using Maven, modify the pom.xml to include the poi-ooxml library .如果使用 Maven,请修改 pom.xml 以包含poi-ooxml 库 Transitive dependencies are taken care of by Maven.传递依赖由 Maven 处理。

Please share exact exception trace and your environment details to help you further.请分享确切的异常跟踪和您的环境详细信息,以进一步帮助您。 I would not recommend to add the third party libraries to Java lib directory as it might add conflicts in future with other projects.我不建议将第三方库添加到 Java lib 目录,因为它可能会在未来与其他项目添加冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM