Hi,
Anyone knows how to create a MS Excel file using java,i was tring to create
a file but it gives a exception when i run the programe.I'm using Apache PIO
API in eclips, for the my program.please help me to over come this problem.
Thanxx
Code
************************************************************************************************************************
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.Region;
//import org.apache.poi.hssf.uti.*;
public class xxxxxx {
private static HSSFRow columnHeaderRow;
private static HSSFCell totalValue;
@SuppressWarnings("deprecation")
public static void main(String []args){
HSSFWorkbook workBook=new HSSFWorkbook();
HSSFSheet sheet = workBook.createSheet();
HSSFRow headerRow = sheet.createRow((short) 0);
sheet.addMergedRegion(new Region(0, (short) 0, 2,(short) 10));
HSSFCell headerCell = headerRow.createCell((short) 0);
headerCell.setCellValue("The Bowling Score");
HSSFCellStyle headerStyle =workBook.createCellStyle();
headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
headerCell.setCellStyle(headerStyle);
HSSFCellStyle columnHeaderStyle =workBook.createCellStyle();
columnHeaderStyle.setFillBackgroundColor(HSSFColor.BLUE_GREY.index);
columnHeaderStyle.setFillForegroundColor(HSSFColor.BLUE_GREY.index);
HSSFFont font = workBook.createFont();
font.setColor(HSSFFont.COLOR_RED);
columnHeaderStyle.setFont(font);
HSSFCell colHeading1 = columnHeaderRow.createCell((short) 0);
HSSFCell colHeading2 =columnHeaderRow.createCell((short) 4);
colHeading1.setCellStyle(columnHeaderStyle);
colHeading2.setCellStyle(columnHeaderStyle);
HSSFRow row1 = sheet.createRow((short) 5);
HSSFRow row2 = sheet.createRow((short) 6);
HSSFRow row3 = sheet.createRow((short) 7);
HSSFRow row4 = sheet.createRow((short) 8);
HSSFRow row5 = sheet.createRow((short) 9);
// create the 2 cells for each row
HSSFCell c11 = row1.createCell((short) 0);
HSSFCell c12 = row1.createCell((short) 4);
HSSFCell c21 = row2.createCell((short) 0);
HSSFCell c22 = row2.createCell((short) 4);
HSSFCell c31 = row3.createCell((short) 0);
HSSFCell c32 = row3.createCell((short) 4);
HSSFCell c41 = row4.createCell((short) 0);
HSSFCell c42 = row4.createCell((short) 4);
// writing data to the cells
c11.setCellValue("Sam");
c12.setCellValue(100);
c21.setCellValue("John");
c22.setCellValue(50);
c31.setCellValue("Paul");
c32.setCellValue(25);
c41.setCellValue("Richard");
c42.setCellValue(20);
totalValue.setCellType(HSSFCell.CELL_TYPE_FORMULA);
totalValue.setCellFormula("SUM(E6:E9)");
FileOutputStream stream;
try {
stream = new FileOutputStream("Book1.xls");
workBook.write(stream);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
*******************************************************************************************
This is the Excception
************************************
org.apache.poi.hssf.dev.BiffViewer$CommandParseException: Biff viewer needs
a filename
at
org.apache.poi.hssf.dev.BiffViewer$CommandArgs.parse(BiffViewer.java:321)
at org.apache.poi.hssf.dev.BiffViewer.main(BiffViewer.java:370)
Regards ,
Udeshika Perera.
--
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en