Please find a Code snippet below
public class DataDriven_GetDataExcel {
public static void main(String[] args) throws IOException, EncryptedDocumentException, InvalidFormatException {
//1 Getting Control over File
FileInputStream fis = new FileInputStream("C:\\Users\\bewosaurabh\\Documents\\GetDataFile.xlsx");
//2 Creating a Workbook
Workbook wb = WorkbookFactory.create(fis);
//3 Getting Control over Sheet
Sheet sh = wb.getSheet("Sheet1");
.
......
What I don't understand is why we need to create a Workbook before reading the Excel file? An Excel file is also called as Workbook (as we can see in below picture).
When we Create an excel file that means we are creating a Workbook. From there, we access the Sheets followed by rows and columns.
I don't understand why we write write WorkbookFactory.create(fis);
when we already have a 'Workbook'
We should have some methods to get the Workbook we have created like we have for Rows(getRow), Sheets (getSheet), Cells (getCell).
Can you help me understand POI?
WorkbookFactory.create
does not create a workbook (an Excel file). It instantiates a class that represents a workbook. – GSerg