java 创建xls文件实战

来源:互联网 发布:acronis备份软件 编辑:程序博客网 时间:2024/04/30 06:56
WritableWorkbook workbook = Workbook.createWorkbook(new File("d:/test.xls"));

        WritableSheet sheet 
= workbook.createSheet("test"0);
        
int col = 0;
        
int line = 0;

        WritableCellFormat style 
= new WritableCellFormat(new WritableFont(
                WritableFont.ARIAL, 
10, WritableFont.BOLD, false,
                UnderlineStyle.NO_UNDERLINE, Colour.BLACK));
        sheet.addCell(
new Label(col++, line, "usernate", style));
        sheet.addCell(
new Label(col++, line, "date", style));
        sheet.addCell(
new Label(col++, line, "Pic Qty", style));
        sheet.addCell(
new Label(col++, line, "Price (HKD) per picture", style));
        sheet.addCell(
new Label(col++, line, "Total ", style));
        String[] data 
= "beauty""2007-10-15""20""15.70""20.50" };
        
for (int i = 0; i < 20; i++{
            col 
= 0;
            line
++;
            sheet.addCell(
new Label(col++, line, data[0], style));
            sheet.addCell(
new Label(col++, line, data[1], style));
            sheet.addCell(
new Label(col++, line, data[2], style));
            sheet.addCell(
new Label(col++, line, data[3], style));
            sheet.addCell(
new Label(col++, line, data[4], style));
        }

        line 
+= 3;
        sheet.addCell(
new Label(4, line, "total", style));
        line
++;
        sheet.addCell(
new Label(4, line, "159", style));
        workbook.write();
        workbook.close();
 小说明一下,需要jxl.jar
原创粉丝点击