I am trying to use the apache poi api. I have downloaded the jar libraries. This is the code that I have written. The name of the file is Main.java.
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
File inputFile = new File(".\test.xlsx");
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(inputFile));
HSSFSheet sheet = workbook.getSheetAt(0);
Cell cell;
Row row;
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()){
row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()){
cell = cellIterator.next();
System.out.println(cell.getStringCellValue());
}
}
}
}
This what I code that I am running the compile the file.
javac -cp "./poi-3.12-20150511.jar;./poi-ooxml-3.12-20150511.jar;./poi-ooxml-schemas-3.12-20150511.jar" Main.java
I am not getting any errors while I am compiling. But when I am trying to run it I am getting a class not found exception for HSSFWorkbook. What am I doing wrong.
PS - All the jar files and my java code are in the same folder.
Try this:
java -cp "poi-3.12-20150511.jar;poi-ooxml-3.12-20150511.jar;poi-ooxml-schemas-3.12-20150511.jar;." Main