gpt4 book ai didi

java - Maven 和 POI : package error and to compile the code

转载 作者:太空宇宙 更新时间:2023-11-04 12:01:08 25 4
gpt4 key购买 nike

我有以下代码:

    import java.io.*;
import org.apache.poi.hssf.usermodel.*;



public class CreateWorkBook
{
public static void main(String[] args)throws Exception
{
//Create Blank workbook
HSSFWorkbook workbook = new HSSFWorkbook();
//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");
}
}

但是 Eclipse 环境提示以下行:

HSSFWorkbook workbook = new HSSFWorkbook();

它说:

  • HSSFWorkbook cannot be resolved to a type

我已正确加载包:import org.apache.poi.hssf.usermodel.*;

有关详细信息,请查看 pom.xml 文件:

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.x.java</groupId>
<artifactId>ExcelPass</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>ExcelPass</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>

为什么这么要求?我的配置有什么问题?

感谢您的帮助。

最佳答案

Eclipse 中删除该项目,然后再次重新导入。这应该可以解决您的问题。

关于java - Maven 和 POI : package error and to compile the code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40894236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com