file name seems wrong [color=#FF0000:2yjlny40]test.xlsx.xls[/color:2yjlny40]
I dont think the file name should have any concerns here because its just as good as any other name like abc.xyz.xls.
However, I tried changing the file name and the file name in the code as well. But its giving the same error.
Hoping for Ashish to look into. I am sure, he will need no time to give a solution for this.
I tried googling but no solution I got. Requesting to please help out on this. The changed code looks like;
public class TestRedingfromxls {
public static void main(String[] args) throws IOException {
File First_File=new File("D:\\Temp\\test.xls");
Workbook wb=new WorkbookFactory.create(inp);
No, I have not tried with xls_Reader as I wanted to understand that in depth.
The intention is that if I use XLS_Reader, I may not be able to answer interview question as I use the ready-made methods written in XLS_Reader.
Please help me in understanding it in the best way so that i am able to answer for Interview questions like how do your read data from your xls in your data driven framework.
try this.
[code:gdcp7j90]
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class SimpleExcelReaderExample {
public static void main(String[] args) throws IOException {
String excelFilePath = "D:\\Vaibhav\\xampp\\htdocs\\newexerise\\files_dir\\1.xlsx";//put any xlsx file here
FileInputStream inputStream = new FileInputStream(new File(excelFilePath));
Workbook workbook = new XSSFWorkbook(inputStream);
Sheet firstSheet = workbook.getSheetAt(0);// sheet number 0 or 1 etc
Iterator<Row> iterator = firstSheet.iterator();
while (iterator.hasNext()) {
Row nextRow = iterator.next();
Iterator<Cell> cellIterator = nextRow.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
System.out.print(cell.getStringCellValue());
break;
case Cell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue());
break;
case Cell.CELL_TYPE_NUMERIC:
System.out.print(cell.getNumericCellValue());
break;
}
System.out.print(" - ");
}
System.out.println();
}
workbook.close();
inputStream.close();
}
}[/code:gdcp7j90]