Reading xls using POI ("Poor Obfuscation Implementation")

10:07 PM 0 Comments

Program to Read the xls using the POI as Follows:

1. Download the poi related jars and add the jars to the build path.
Link to download POI jars..

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

public class ReadExcelPoi {


public static void main() throws InvalidFormatException, FileNotFoundException, IOException{

Workbook wb=WorkbookFactory.create(new FileInputStream(new File("inputData.xlsx")));

Sheet sh1=wb.getSheetAt(0);

int rows=sh1.getLastRowNum();

for(int i=0;i<rows+1;i++){

String data1=sh1.getRow(i).getCell(0).getStringCellValue();
String data2=sh1.getRow(i).getCell(1).getStringCellValue();

System.out.println("Data from First column and from row "+i+" is "+data1);
System.out.println("Data from Second column and from row "+i+" is "+data2);
System.out.println("===========================================");
}

}
}

.xls File

Unknown

This site creates a platform to become an expert by gaining knowledge of unknown real-time issues as well.

0 comments: