我想从具有Java库Apache Poi的excel .xlsx文件中读取,但是我无法修复错误,代码无法编译

时间:2018-08-08 10:24:42

标签: java excel apache-poi

我正在youtube上观看一段视频,以使用apache poi读取excel文件,但似乎我的代码无法编译,而我的行为完全像youtube上的家伙一样

写作部分效果很好,但我仍在复制它,因为我认为它可能会影响阅读部分。另外,我正在分享我在youtube上关注的视频的链接。

package amalyze;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;



public class Amalyze {

private static Workbook wbR;
private static Sheet sheetR;
private static FileInputStream fis;
private static FileOutputStream fos;
private static Row rowR;
private static Cell cellR;


    public static void main(String[] args) throws IOException, Exception{


        //Reading part
        fis = new FileInputStream("./amzdata.xlsx");
        wbR = WorkbookFactory.create(fis);
        sheetR =wbR.getSheet("Sheet1");







        // Writing Part
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet("FirstExcelSheet");
        HSSFRow row = sheet.createRow(0);
        HSSFCell cell = row.createCell(7);
        cell.setCellValue("str");
        workbook.write(new FileOutputStream("Excelamz.xls"));
        workbook.close();





    }

}

Snippet of error description Tutorial Video

1 个答案:

答案 0 :(得分:2)

您可能缺少xmlbeans传递依赖项。

http://mvnrepository.com/artifact/org.apache.xmlbeans/xmlbeans

我建议使用Maven或Gradle来管理您的依赖项。