Featured Post

Generating XLS using Java

Hi Friends ,


Please find below code for generating excel sheet using java









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;

/**
* This is a sample to create an Excel Sheet using Jakarta POI API
*
* @author Venkata Sitaram Pilaka
* @version 1.0
*/
public class A {
/** A place for the output Excel file to go */
public static String outputFile = "java.xls";

public static void main(String argv[]) {
try {
// Create a New XL Document
HSSFWorkbook wb = new HSSFWorkbook();
// Make a worksheet in the XL document created
HSSFSheet sheet = wb.createSheet();
// Create row at index zero ( Top Row)
HSSFRow row = sheet.createRow((short) 0);
// Create a cell at index zero ( Top Left)
HSSFCell cell = row.createCell((short) 0);
// Lets make the cell a string type
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
// Type some content
cell.setCellValue(1234567.0);
// cell.setCellValue(“This is Nitin’s Sample Code”);
// The Output file is where the xls will be created
FileOutputStream fOut = new FileOutputStream(outputFile);
// Write the XL sheet
wb.write(fOut);
fOut.flush();
// Done Deal..
fOut.close();
System.out.println("File Created ..");

} catch (Exception e) {
System.out.println("Exception while creating XLS " + e);
}

}

}



Comments

Popular posts from this blog

[Inside AdSense] Understanding your eCPM (effective cost per thousand impress...