Netbeans org.apache.poi - cannot access Date1904Su

2019-08-27 08:18发布

问题:

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

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

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;

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>

I am not sure where is the problem

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");
        }
    }