Netbeans org.apache.poi - 无法访问 Date1904Support [英] Netbeans org.apache.poi - cannot access Date1904Support

查看:82
本文介绍了Netbeans org.apache.poi - 无法访问 Date1904Support的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 NetBeans IDE 8.2 中创建 Csv2Xlsx 应用程序,但出现此错误:

I am creating Csv2Xlsx app in NetBeans IDE 8.2 and I got this error:

--- maven-compiler-plugin:2.3.2:compile (default-compile) @ csv2xlsx ---
Compiling 1 source file to C:\Users\test\Documents\NetBeansProjects\csv2xlsx\target\classes
-------------------------------------------------------------
COMPILATION ERROR : 
-------------------------------------------------------------
com/test/csv2xlsx/Csv2Xlsx.java:[74,38] error: cannot access Date1904Support
1 error
-------------------------------------------------------------
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.320s
Finished at: Fri May 24 06:57:36 CEST 2019
Final Memory: 17M/347M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project csv2xlsx: Compilation failure
com/test/csv2xlsx/Csv2Xlsx.java:[74,38] error: cannot access Date1904Support
-> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

这是我在项目中的所有依赖项

this is my all Dependencies in project

java 文件中的错误行是这个

error row in java file is this

XSSFSheet sheet = workBook.createSheet("Data"); // com/test/csv2xlsx/Csv2Xlsx.java:[74,38] error: cannot access Date1904Support

但没有红色下划线,尝试编译后给我这个错误

but nothing is underlined by red color, after try to compile give me this error

在我的 Csv2Xlsw java 文件中,我导入了这些命名空间:

in my Csv2Xlsw java file I import these namespaces:

import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;

import org.apache.log4j.Logger;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFSheet;

这是我的 POM 文件

this is my POM file

<?xml version="1.0" encoding="UTF-8"?>
<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>com.test</groupId>
    <artifactId>csv2xlsx</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.8</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <name>Csv2Xlsx</name>
    <description>Convert CSV file to Xlsx (Excel) file</description>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我不知道问题出在哪里

public void convert(String sourceCSV, String targetXLSX) throws IOException,
            NumberFormatException {
        try {

            XSSFWorkbook workBook = new XSSFWorkbook();
            XSSFSheet sheet = workBook.createSheet("Data"); // com/test/csv2xlsx/Csv2Xlsx.java:[74,38] error: cannot access Date1904Support
            String currentLine = null;
            int RowNum = 0;
            BufferedReader br = new BufferedReader(new FileReader(sourceCSV));

            while ((currentLine = br.readLine()) != null) {
                String str[] = currentLine.split(delimiter);
                RowNum++;
                Row currentRow = sheet.createRow(RowNum);
                for (int i = 0; i < str.length; i++) {
                    currentRow.createCell(i).setCellValue(str[i]);
                }
            }

            try (FileOutputStream fileOutputStream = new FileOutputStream(targetXLSX)) {
                workBook.write(fileOutputStream);
            }
            System.out.println("Done");
        } catch (IOException | NumberFormatException ex) {
            System.out.println(ex.getMessage() + "Exception in try");
        }
    }

推荐答案

poi 和 poi-ooxml 的版本应该是一样的,这样你就不会再遇到这个问题了.转到您的 pom.xml 以验证版本号并相应地更新它们.

The version of poi and poi-ooxml should be the same and then you won't get this problem anymore. Go to your pom.xml to verify the version number and update them accordingly.

这篇关于Netbeans org.apache.poi - 无法访问 Date1904Support的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆