Jenkins with Hithub

Jenkins with Hithub

Reading xls using POI ("Poor Obfuscation Implementation")

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

Reading xls using JXL (Java Excel Library)!!

Program to Read the xls using the JExcel as Follows:

1. Download the JXL jar from the following location. Add the jar to the Build Path of the project.
 http://mirrors.ibiblio.org/pub/mirrors/maven/net.sourceforge.jexcelapi/jars/jxl-2.6.jar

2. Link for JXL API.  http://jexcelapi.sourceforge.net/

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;


public class ReadExcel {

public static void main(String[] args) throws BiffException, IOException {

File f = new File("inputData.xls");
Workbook w = Workbook.getWorkbook(f);
Sheet sheet = w.getSheet(0);
int rows = sheet.getRows();
int cols=sheet.getColumns();
String inputData[][] =new String[rows][cols];
for(int i =0;i<rows;i++)
{
for(int j=0;j<cols;j++)
{
Cell cell =sheet.getCell(j,i);//Column , row
String str =cell.getContents();
System.out.print(str);
inputData[i][j]= str;
}
System.out.println();
}
}

}

.xls File