Finding last column cell values. if cell value is "Not Valid" or "Not Applicable", delete the entire row.
The code I have written so far is as follows:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.usermodel.Workbook;
public class Column
{
public static void main(String[] args) throws InvalidFormatException, FileNotFoundException, IOException
{
try
{
Workbook wb = WorkbookFactory.create(new FileInputStream("C:/Users/Excel1.xlsx"));
Sheet sheet = wb.getSheet("Retail-All");
Workbook wb2 = new HSSFWorkbook();
wb2 = wb;
Row row;
row = sheet.getRow(0);
int getLastCell=row.getLastCellNum()-1;
int lastIndex = sheet.getLastRowNum();
for (int i=0; i<=lastIndex; i++)
{
row=sheet.getRow(i);
if(row.getCell(getLastCell)!=null && (row.getCell(getLastCell).toString().equalsIgnoreCase("Not valid) || row.getCell(getLastCell).toString().equalsIgnoreCase("Not Applicable")))
{
sheet.removeRow(row);
//sheet.shiftRows(i, lastIndex, -1);
}
}
FileOutputStream fileOut = new FileOutputStream("C:/Users/shiftRows.xlsx");
wb2.write(fileOut);
fileOut.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
With the above code, using row.setZeroHeight(true); method I can able to hide the rows.
With the above code, using sheet.removeRow(row); method I can able to empty all the cells in that particular row.
I found some code in net, but none of them are deleting the rows permanently.My requirement is to delete the rows permanently. How to code to meet my requirement?
Perhaps using a VBA macro would be more helpful in this situation? VBA macros can be embedded into your spreadsheet, so running them could be a lot easier.
Here is a good place to get started with VBA:
http://msdn.microsoft.com/en-us/library/office/ee814737(v=office.14).aspx
Try this one...
SVTableModel model = new SVTableModel(sheet);
int lastIndex = model.getRowCount();
for (int i=1; i<=lastIndex; i++)
{
row=sheet.getRow(i);
if((row.getCell(getLastCell)!=null) && (row.getCell(getLastCell).toString().equalsIgnoreCase("Not valid") || row.getCell(getLastCell).toString().equalsIgnoreCase("Not Applicable")))
{
row.setZeroHeight(true);
sheet.removeRow(row);
}
Instead of sheet.removeRow(row); you can use the shiftRows(int startRow, int endRow, int n) instruction, that seems you have tried, that shifts rows between startRow and endRow n number of rows.
In your case it will be
// ... code before ...
for (int i=0; i<=lastIndex; i++)
{
row=sheet.getRow(i);
if(row.getCell(getLastCell)!=null && (row.getCell(getLastCell).toString().equalsIgnoreCase("Not valid") || row.getCell(getLastCell).toString().equalsIgnoreCase("Not Applicable")))
{
// This should shift up by 1 row all the rows below
sheet.shiftRows(i+1, lastIndex, -1);
i--; // Since you move row at i+1 to i you have to recompute the i-th row
}
}
// ... code after ...
Check org.apache.poi.hssf.usermodel.HSSFSheet Documentation for more information
Please try the below code. My last cell value is Mismatched ot
Matched. Set as per ur excel.
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class DeleteAllRecord {
public static void main(String[] args) {
try{
File src= new File("testdata\\OSBC.xlsx");
FileInputStream fis= new FileInputStream(src);
XSSFWorkbook workbook= new XSSFWorkbook(fis);
XSSFSheet data= workbook.getSheet("TestData");
int length=data.getLastRowNum();
XSSFSheet data1;
Row row1;
for(int i=1;i<=length;i++){
String testCaseNo=data.getRow(i).getCell(4).toString();
System.out.println("The Testcase no "+testCaseNo);
data1= workbook.getSheet(testCaseNo);
row1 = data1.getRow(2);
int getLastCell=row1.getLastCellNum()-1;
System.out.println("The last cell is "+getLastCell);
int lastIndex = data1.getLastRowNum();
System.out.println("The last row is "+lastIndex);
String str1= row1.getCell(getLastCell).toString();
System.out.println("The valu1 is "+ str1);
for (int j=0; j<lastIndex-1; j++)
{
String str=data1.getRow(j+2).getCell(getLastCell).toString();
row1=data1.getRow(j+2);
System.out.println("print " + (j+2) +str);
if(row1.getCell(getLastCell)!=null &&
(row1.getCell(getLastCell).toString().equalsIgnoreCase("MATCHED")||
row1.getCell(getLastCell).toString().equalsIgnoreCase("MISMATCHED")||
row1.getCell(getLastCell).toString().equalsIgnoreCase(""))){
data1.removeRow(row1);
System.out.println("print " + (j+2)+ " " +str);
}
else{
System.out.println("Null");
}
}
FileOutputStream fileOut = new FileOutputStream("testdata\\delete.xlsx");
workbook.write(fileOut);
fileOut.close();
System.out.println("File deleted");
}
}
catch(Exception e){
System.out.println("No Data Exists to delete");
}
}
}
Related
I am struggling through this IBAN Checker JAVA project where I am supposed to take IBANs from an excel sheet -> validate them -> print valid/invalid results back into Excel. I have it almost all set up but now I got stuck on looping function that should put already validated IBANS back to the sheet. Here I am getting only last IBAN number of my IBAN Array which gets printed into all the rows, other IBANs are not showing.
However, when I use "System.out.printf("%s is %s.%n", iban, validateIBAN(iban) ? "valid" : "not valid");" function all the ibans are validated correctly and printed into console one by one.
Is there please some way to get the results of above "System.out.printf" and iterate them through the cells in the Excel sheet? Or would you have some suggestion for modifications of the for-loop please? I think something in the loop is causing the issue because when I put "System.out.prinf" function inside of the loop, it starts validating only the last IBAN number which means something with the loop is not right.
Thank you very much for any help you can give!
IBANChecker03.java
package ibanchecker03;
import java.math.BigInteger;
import java.util.*;
//EXCEL
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
//EXCEL
public class IBANChecker03 {
private static final String DEFSTRS = ""
+ "AL28 AD24 AT20 AZ28 BE16 BH22 BA20 BR29 BG22 "
+ "HR21 CY28 CZ24 DK18 DO28 EE20 FO18 FI18 FR27 GE22 DE22 GI23 "
+ "GL18 GT28 HU28 IS26 IE22 IL23 IT27 KZ20 KW30 LV21 LB28 LI21 "
+ "LT20 LU20 MK19 MT31 MR27 MU30 MC27 MD24 ME22 NL18 NO15 PK24 "
+ "PS29 PL28 PT25 RO24 SM27 SA24 RS22 SK24 SI19 ES24 SE24 CH21 "
+ "TN24 TR26 AE23 GB22 VG24 GR27 CR21";
private static final Map<String, Integer> DEFINITIONS = new HashMap<>();
static {
for (String definition : DEFSTRS.split(" "))
DEFINITIONS.put(definition.substring(0, 2), Integer.parseInt(definition.substring(2)));
}
public static void printValid(String iban) throws FileNotFoundException, IOException, InvalidFormatException {
File file = new File("G:\\AR\\INVprint (GD Thomas)\\EKG.xls");
FileInputStream ExcelFile = new FileInputStream(file);
HSSFWorkbook wb = new HSSFWorkbook(ExcelFile);
HSSFSheet sheet = wb.getSheet("SheetF");
System.out.printf("%s is %s.%n", iban, validateIBAN(iban) ? "valid" : "not valid");
try {
for (int rowNumber = 0; rowNumber < sheet.getLastRowNum(); rowNumber++) {
HSSFRow row1 = sheet.getRow(rowNumber);
HSSFCell cell = row1.createCell(1);
cell.setCellValue(iban + " is " + validateIBAN(iban));
//System.out.println(cell);
//for(int columnNumber = 1; columnNumber < row1.getLastCellNum();) {
// HSSFCell cell = row1.createCell(columnNumber);
// if(cell != null) {
//cell.setCellValue("Darkness");
//System.out.println(cell);
}
// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("G:\\AR\\INVprint (GD Thomas)\\EKG.xls");
wb.write(fileOut);
wb.close();
} catch (FileNotFoundException e) {
throw new FileNotFoundException("File not faaund");
}
}
public static void main(String[] args) throws IOException, FileNotFoundException {
String[] ibans = {"GB33BUKB20201555555555"};
for (String iban : ibans) {
try {
printValid(iban);
} catch (InvalidFormatException ex) {
Logger.getLogger(IBANChecker03.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
static boolean validateIBAN(String iban) {
iban = iban.replaceAll("\\s", "").toUpperCase(Locale.ROOT);
int len = iban.length();
if (len < 4 || !iban.matches("[0-9A-Z]+") || DEFINITIONS.getOrDefault(iban.substring(0, 2), 0) != len)
return false;
iban = iban.substring(4) + iban.substring(0, 4);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < len; i++)
sb.append(Character.digit(iban.charAt(i), 36));
BigInteger bigInt = new BigInteger(sb.toString());
return bigInt.mod(BigInteger.valueOf(97)).intValue() == 1;
}
}
HomeOffice.java
package ibanchecker03;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class HomeOffice {
public static void main(String[] args) throws Exception {
File excelFile = new File("G:\\AR\\INVprint (GD Thomas)\\TEST2 IBAN.xlsx");
FileInputStream fis = new FileInputStream(excelFile);
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
//Here we start iterating through raws and cells
Iterator<Row> rowIt = sheet.iterator();
while (rowIt.hasNext()) {
Row row = rowIt.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
if (cell.getColumnIndex() == 7) { // Choose number of column
//System.out.println(cell.toString() + ","); // Print cells
String cellvalue = cell.toString();
IBANChecker03.printValid(cellvalue);
}
}
workbook.close();
fis.close();
}
}
}
i'm trying to read data from excel and plot graph using java.
I keep getting the below error:
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/util/PublicCloneable
My code:
import java.io.*;
import java.util.*;
import org.jfree.data.*;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.plot.PlotOrientation;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.jfree.data.category.DefaultCategoryDataset;
public class ReadExcel{
public static void main(String[]args){
short a=0;
short b=1;
int i=0;
ArrayList<Integer> list1=new ArrayList<Integer>();
ArrayList<Integer> list2=new ArrayList<Integer>();
int x=0, y=0;
String filename ="C:\\Chart.xlsx";
if(filename != null && !filename.equals("")){
try{
FileInputStream fs =new FileInputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook(fs);
for(int k = 0; k < wb.getNumberOfSheets(); k++){
int j=i+1;
HSSFSheet sheet = wb.getSheetAt(k);
int rows = sheet.getPhysicalNumberOfRows();
for(int r = 1; r < rows; r++){
HSSFRow row = sheet.getRow(r);
int cells = row.getPhysicalNumberOfCells();
HSSFCell cell1 = row.getCell(a);
x =(int) cell1.getNumericCellValue();
HSSFCell cell2 = row.getCell(b);
y =(int) cell2.getNumericCellValue();
list1.add(new Integer(x));
list2.add(new Integer(y));
}
i++;
}
}catch(Exception e){
System.out.println(e);
}
}
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int j=0;j<list1.size();j++){
dataset.setValue((double)list2.get(j), "Marks", list1.get(j).toString());
}
JFreeChart chart = ChartFactory.createBarChart("BarChart using JFreeChart","ID", "Marks", dataset,
PlotOrientation.VERTICAL, false,true, false);
try {
ChartUtilities.saveChartAsJPEG(new File("C:\\chart.jpg"), chart,400, 300);
} catch (IOException e) {
System.out.println("Problem in creating chart.");
}
}
}
Sample excel:
Response Time Transaction Name Runid
25 Home 1
56 Login 2
23 Order 3
i tried to use the XSSF Apache POI but no luck.
I also wanted to save the image of the chart somewhere locally.
NoClassDefFoundError means that the JVM is unable to find a class that you're using in your code. In a general way, it means you're missing a dependency in your classpath. Try adding this dependency to your project: https://mvnrepository.com/artifact/org.jfree/jcommon
I am reading xlsx file using Apache POI. I am able to fetch the result and xlsx entities count successfully. but I want to get my result in JSON, so that I can use this JSON data to make google graph or any graph API. I am new to java, how can I do that? Any help will be appreciated.
My code details are below.
package com.amiku.Excel;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.*;
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.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelReader
{
public static void main(String[] args) throws IOException{
{
FileInputStream fis = new FileInputStream(new File("C:\\Users\\amiku\\eclipse-workspace\\Amiku\\cloudstreams-connectors-downloads.xlsx"));
//create workInstance that refers to .xlsx file
XSSFWorkbook wb = new XSSFWorkbook(fis);
//create a sheet object to retrive the sheet
XSSFSheet sheet = wb.getSheetAt(0);
//that is for evalute the cell type
FormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
Map<String, Integer> Details = new HashMap<String,Integer>();
int i=0;
List<String> l = new ArrayList<String>();
for (Row row : sheet)
{
for (Cell cell : row) {
l.add(cell.getStringCellValue());
/*HashMap map = new HashMap();
map.put(cell.getStringCellValue());*/
}
/*switch(formulaEvaluator.evaluateInCell(cell).getCellType())
{*/
/*//if cell has a numeric format
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue() + "\t\t");
break;
// if cell has a string format
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue() + "\t\t");
break;
}*/
i++;
System.out.println();
}
for (int j = 0; j < l.size(); j++) {
if (j % 2 == 1) {
String var = l.get(j);
if (Details.containsKey(var)) {
Details.put(var, Details.get(var) + 1);
} else {
Details.put(var, 1);
}
}
}
Iterator it = Details.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
System.out.println(pair.getKey() + " = " + pair.getValue());
it.remove(); // avoids a ConcurrentModificationException
}
}
}
}
my result image of this code is here.
you can create a expandible object and add key value pair to this object ,once all of your javacode output is set into this object,
simply serialize this object to json using one of the speficied library.
I am facing issues in print preview with xls generated using apache POI. I have used HSSFRichTextString to apply styling to cell content.For text I`m applying Arial font & for numbers within cell content i am using Terminal font.
E.g "SS 123 RR" SS/RR will be in Arial, 123 will be in Terminal.
Below is code snippet for the same.
package com.adp.wfn.payroll.exportToExcel;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Arrays;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class ReadAndWriteRichText {
public static void main(String[] args) {
try {
InputStream inp = new FileInputStream("/home/devel/Desktop/hi/CheckRegister_Template.xls");
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(1);
Cell cell = row.createCell(1);
Font font1 = workbook.getFontAt(cell.getCellStyle().getFontIndex());
System.out.println(font1);
Font font2 = workbook.createFont();
font2.setFontName("Terminal");
font2.setFontHeightInPoints(font1.getFontHeightInPoints());
System.out.println(font2);
String originalStr="ss 123 ss";
HSSFRichTextString richString = new HSSFRichTextString( "SS 123 SS 44" );
cell.setCellValue( formatNumbersOfCellText(originalStr,font2,font1) );
FileOutputStream out = new FileOutputStream(
new File("/home/devel/Desktop/createworkbookRaj.xlsx"));
workbook.write(out);
out.close();
System.out.println("createworkbook.xlsx written successfully");
} catch (Exception ex) {
}
}
private static HSSFRichTextString formatNumbersOfCellText(String outputString,Font numberFont, Font strFont){
HSSFRichTextString formattedString = null;
try{//"ss 123 nn 67"
if(null != outputString && !outputString.trim().equalsIgnoreCase("")){
int lstIndexCalculated=0;
int startIndex ;
int endIndex;
String[] splittedArr = outputString.split("\\s");
if(null != splittedArr && splittedArr.length > 0){
formattedString = new HSSFRichTextString(outputString);
for (int i = 0; i < splittedArr.length; i++) {
if(lstIndexCalculated == 0){
startIndex = outputString.indexOf(splittedArr[i]);
}else{
startIndex = outputString.indexOf(splittedArr[i],lstIndexCalculated);
if(lstIndexCalculated < startIndex){
formattedString.applyFont(lstIndexCalculated,startIndex ,numberFont);
}
}
endIndex = startIndex + (splittedArr[i].length());
lstIndexCalculated = endIndex;
if(isNumericField(splittedArr[i])){
formattedString.applyFont(startIndex,endIndex ,numberFont);
}else{
formattedString.applyFont(startIndex,endIndex ,strFont);
}
startIndex = 0;
endIndex = 0;
}
if(lstIndexCalculated != 0){
return formattedString;
}
}
}
}catch(Exception e){
return null;
}
return null;
}
private static boolean isNumericField(String inputStr){
if(null != inputStr && !inputStr.trim().equalsIgnoreCase("")){
try{
inputStr = inputStr.replaceAll("[(,)]", "");
Double value = Double.valueOf(inputStr);
return true;
}catch(NumberFormatException numFormatExp){
return false;
}catch (Exception e) {
return false;
}
}
return false;
}
}
Now when i open generated xls I see formatting applied to contents.
Please refer xls view for the same.
But now when i do print preview I see issue with font. Terminal font which applied for numbers is no longer visible in print preview. Please refer enter image description here for print preview view.
Note the difference between number '1' in both images.
Any idea/suggestion how do i overcome this ?
Thanks In advance.
I am writing a Java program to read data from excel sheet (having XLSX extension) using Apache POI library. I am able to iterate through all the cells and get all the values. But I am unable to get a specific cell value, say E10.
Is there any way to do this?
Please see the code below that I used for iterating through the cells.
package application;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ReadFromXLSX {
public static void readXLSXFile() throws IOException
{
InputStream ExcelFileToRead = new FileInputStream("C:\\Test.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(ExcelFileToRead);
XSSFWorkbook test = new XSSFWorkbook();
XSSFSheet sheet = wb.getSheetAt(0);
XSSFRow row;
XSSFCell cell;
Iterator rows = sheet.rowIterator();
while (rows.hasNext())
{
row=(XSSFRow) rows.next();
Iterator cells = row.cellIterator();
while (cells.hasNext())
{
cell=(XSSFCell) cells.next();
if (cell.getCellType() == XSSFCell.CELL_TYPE_STRING)
{
System.out.print(cell.getStringCellValue()+" ");
}
else if(cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC)
{
System.out.print(cell.getNumericCellValue()+" ");
}
else
{
}
}
System.out.println();
}
}
}
For example, to get E10 of the first worksheet:
wb.getSheetAt(0).getRow(9).getCell(4);
Note: subtract one because the indices are null-based.
You can also use this convenience method to map E to 4.
wb.getSheetAt(0).getRow(9).getCell(CellReference.convertColStringToIndex("E"));
To get a value from a specific cell in excel you can use the below code line.
wb.getSheetAt(0).getRow(1).getCell(1);
XSSFSheet has the method getRow(int rownum)
It returns the logical row ( 0-based). If you ask for a row that is not defined you get a null. This is to say row 4 represents the fifth row on a sheet.
Once you get the row, you can call getCell(int cellnum) method of XSSFRow object. It returns the cell at the given (0 based) index.
Just version-up the getCell method
public XSSFCell getCell(String cellName){
Pattern r = Pattern.compile("^([A-Z]+)([0-9]+)$");
Matcher m = r.matcher(cellName);
XSSFWorkbook wb = new XSSFWorkbook();
if(m.matches()) {
String columnName = m.group(1);
int rowNumber = Integer.parseInt(m.group(2));
if(rowNumber > 0) {
return wb.getSheetAt(0).getRow(rowNumber-1).getCell(CellReference.convertColStringToIndex(columnName));
}
}
return null;
}
Now you can get the cell easily by this line
getCell("E10")
public class XmlFileRead {
public static void main(String[] args) throws IOException {
FileInputStream fi = new FileInputStream("abc.xls");
ArrayList<EmployeeVo> al = new ArrayList<>();
EmployeeVo evo = null;
Scanner scanner = null;
Workbook wb = new XSSFWorkbook(fi);
Sheet sh = wb.getSheet("Sheet0");
int starRow = sh.getFirstRowNum();
int endRow = sh.getLastRowNum();
for (int i = starRow + 1; i < endRow; i++) {
scanner = new Scanner(System.in);
evo = new EmployeeVo();
Cell c = wb.getSheetAt(0).getRow(i).getCell(1);
evo.setEmployeeId((int) c.getNumericCellValue());
Cell c2 = wb.getSheetAt(0).getRow(i).getCell(2);
evo.setEmployeeName(c2.toString());
// add to collection
al.add(evo);
} // for
al.forEach(i -> {
System.out.println(i.getEmployeeId() + " " + i.getEmployeeName());
});
}
}