March 19, 2009 at 5:38 AM
hi friend
This code really works for you. To run the given code, you have to download the poi-bin-3.1-beta2-20080526.zip(POI.jar) from Apache Jakarta Project.
import java.io.*;
import java.util.Random;
import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.model.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.*;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
public class CreateSpreadsheet {
public static void main (String[] args) throws Exception {
try{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Excel sheet");
HSSFRow row = sheet.createRow((short)0);
HSSFCell cell = row.createCell((short)0);
cell.setCellValue(1);
row.createCell((short)0).setCellValue(" ID");
row.createCell((short)1).setCellValue(" Name ");
row.createCell((short)2).setCellValue(" Address");
HSSFRow row1 = sheet.createRow((short)1);
HSSFCell cell1 = row1.createCell((short)1);
cell.setCellValue(2);
row1.createCell((short)0).setCellValue(1);
row1.createCell((short)1).setCellValue("Angelina ");
row1.createCell((short)2).setCellValue("Delhi");
FileOutputStream fileOut = new FileOutputStream("Hello.xls");
wb.write(fileOut);
fileOut.close();
}catch ( Exception ex ){
}
}
}
Thanks
RoseIndia Team