To Import the data and Write it in excel file. this is could be the one of teh way
package dDT1;
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class Iterator{
public static void main (String[] args){
// Name of excel file that we are going to create
String fileName ="C:\\TEMP\\testdata.xls";
writeDataToExcelFile(fileName);
}
// This method write data to excel file
private static void writeDataToExcelFile(String fileName)
{
String[][] excelData = prepareDataToWriteInExcel();
HSSFWorkbook workBook = new HSSFWorkbook();
HSSFSheet sheet =workBook.createSheet();
HSSFRow row =null;
HSSFCell cell = null;
for(int rowNum=0;rowNum < excelData[0].length;rowNum++)
{
row= sheet.createRow(rowNum);
for (int cellNum = 0;cellNum < 4;cellNum++)
{
cell= row.createCell(cellNum);
cell.setCellValue(excelData[rowNum][cellNum]);
}
}
try{
FileOutputStream out =new FileOutputStream(fileName);
workBook.write(out);
out.close();
}
catch(Exception e){
e.printStackTrace();
}
// return excelData;
}
// created some demo date for excel sheet
public static String [][] prepareDataToWriteInExcel(){
String [][] excelData = new String[4][4];
excelData[0][0]="First Name";
excelData [0][1]="Last Name";
excelData[0][2]="EmpNo";
excelData[0][3]="Sal";
excelData[1][0]="Sachin";
excelData[1][1]="Gainewar";
excelData[1][2]="003";
excelData[1][3]="1500000";
excelData[2][0]="Pravin ";
excelData[2][1]="Balpande";
excelData[2][2]="004";
excelData[2][3]="1800000";
excelData[3][0]="Nilesh";
excelData[3][1]="Thakare";
excelData[3][2]="005";
excelData[3][3]="2100000;
return excelData;
}
}