import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Excel2 {
static Object[][] nana = null;
public static void read() throws IOException, IOException {
String filepath = "C:\\Users\\Mutturaj\\Desktop\\muttu.xlsx";
XSSFWorkbook workbook = new XSSFWorkbook(new FileInputStream(new File(filepath)));
Sheet sheet = workbook.getSheetAt(0);
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
for (Row row : sheet) {
for (Cell cell : row) {
switch (evaluator.evaluateInCell(cell).getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "\t\t");
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t\t");
}
}
System.out.println();
}
}
public static void main(String[] args) throws IOException {
Excel2.read();
}
}
Tuesday, February 19, 2019
FormulaEvaluator in Apache POI
Subscribe to:
Posts (Atom)