Wednesday, August 29, 2007

Create an Microsoft Excel File Using Java Code

/*
* This Example Demonstrate to Create an Microsoft Excel File Using Java Code
*
* For this we need two JAR files poi.jar and commons-logging.jar
*
**/
import java.io.FileOutputStream;

import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class CreateExcel {
public static void main(String[] args) {

try{
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");

HSSFRow row = sheet.createRow((short)0);
row.createCell((short)0).setCellValue("HelloWorld");

FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

0 comments:

BidVertiser