Basic UI Framework

Pragadeeswaran Gnanasekaran
2 min readNov 4, 2023

Create a intellij project maven project

New Maven Project Dialog Box

Once the project is created , you will find the below project structure

Maven Project Structure

This will be hierarchy for apache POI dependency

Excel hierarchy

XLS vs XLSX format

XLS vs XLSX format

Simple Excel Program to read data value

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;

import java.io.IOException;

public class DataLibrary {

public static void main(String[] args) {
XSSFWorkbook xlsx = null;
try{
xlsx = new XSSFWorkbook("/Users/praga/sde/simpleuiframe/data/testdata.xlsx");
XSSFSheet currentSheet = xlsx.getSheet("empdata");
XSSFRow currentRow = currentSheet.getRow(1);
XSSFCell currentCell = currentRow.getCell(0);
System.out.println(currentCell.getStringCellValue());
xlsx.close();
}
catch(IOException e){
e.printStackTrace();
}
}
}

To make the row dynamic we can use below code

currentSheet.getLastRowNum();

getLastRowNum Documentation link

After making the row and column dynamic

package utils;

import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.IOException;

public class DataLibrary {

public static void main(String[] args) {
XSSFWorkbook xlsx = null;
String cellValue = null;
try {
xlsx = new XSSFWorkbook("/Users/praga/sde/simpleuiframe/data/testdata.xlsx");
XSSFSheet currentSheet = xlsx.getSheet("empdata");

System.out.println("total rows excluding header : " + currentSheet.getLastRowNum());
System.out.println("total rows including header : " + currentSheet.getPhysicalNumberOfRows());


for (int i = 1; i <= currentSheet.getLastRowNum(); i++) {
/* XSSFRow currentRow = currentSheet.getRow(i);
XSSFCell currentCell = currentRow.getCell(0);
String cellValue = currentSheet.getRow(i).getCell(0).getStringCellValue();*/
for (int j = 0; j < currentSheet.getRow(i).getLastCellNum(); j++) {
cellValue = currentSheet.getRow(i).getCell(j).getStringCellValue();
System.out.print(cellValue+"\t");
}
System.out.print("\n");

}
xlsx.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

You can find the full code in https://github.com/pragapraga/uiframe

--

--