JAVA生成Excel
来源:互联网 发布:织梦cms视频模板 编辑:程序博客网 时间:2024/04/29 01:54
- WritableWorkbook workbook = Workbook.createWorkbook(new File("d:/test.xls"));
- WritableSheet sheet = workbook.createSheet("工作表名称",0);
- sheet.setColumnView(0,15);
- sheet.setColumnView(1,18);
- sheet.setRowView( 0 ,600 , false );
- sheet.setRowView( 1 ,400 , false );
- sheet.getSettings().setRightMargin( 0.5 );
- sheet.setFooter( "" ,"" , " 测试页脚 " );
-
- WritableFont NormalFont = new WritableFont(WritableFont.ARIAL,10 );
- WritableFont BoldFont = new WritableFont(WritableFont.ARIAL,14 ,
- WritableFont.BOLD);
- WritableFont tableFont = new WritableFont(WritableFont.ARIAL,12 ,
- WritableFont.NO_BOLD);
- WritableFont baodanFont = new WritableFont(WritableFont.ARIAL,10 ,
- WritableFont.BOLD);
-
- WritableCellFormat wcf_title = new WritableCellFormat(BoldFont);
- wcf_title.setBorder(Border.NONE, BorderLineStyle.THIN);
- wcf_title.setVerticalAlignment(VerticalAlignment.CENTRE);
- wcf_title.setAlignment(Alignment.CENTRE);
- wcf_title.setWrap( true );
- WritableCellFormat wcf_tabletitle = new WritableCellFormat(
- tableFont);
- wcf_tabletitle.setBorder(Border.NONE, BorderLineStyle.THIN);
- wcf_tabletitle.setVerticalAlignment(VerticalAlignment.CENTRE);
- wcf_tabletitle.setAlignment(Alignment.CENTRE);
- wcf_tabletitle.setWrap( true );
- WritableCellFormat wcf_left = new WritableCellFormat(NormalFont);
- wcf_left.setBorder(Border.ALL, BorderLineStyle.THIN);
- wcf_left.setVerticalAlignment(VerticalAlignment.CENTRE);
- wcf_left.setAlignment(Alignment.LEFT);
- wcf_left.setWrap( true );
- WritableCellFormat wcf_center = new WritableCellFormat(NormalFont);
- wcf_center.setBorder(Border.ALL, BorderLineStyle.THIN);
- wcf_center.setVerticalAlignment(VerticalAlignment.CENTRE);
- wcf_center.setAlignment(Alignment.CENTRE);
- wcf_center.setWrap( true );
- WritableCellFormat wcf_right = new WritableCellFormat(NormalFont);
- wcf_right.setBorder(Border.ALL, BorderLineStyle.THIN);
- wcf_right.setVerticalAlignment(VerticalAlignment.CENTRE);
- wcf_right.setAlignment(Alignment.RIGHT);
- wcf_right.setWrap( false );
- WritableCellFormat wcf_merge = new WritableCellFormat(NormalFont);
- wcf_merge.setBorder(Border.ALL, BorderLineStyle.THIN);
- wcf_merge.setVerticalAlignment(VerticalAlignment.TOP);
- wcf_merge.setAlignment(Alignment.LEFT);
- wcf_merge.setWrap( true );
- WritableCellFormat wcf_table = new WritableCellFormat(NormalFont);
- wcf_table.setBorder(Border.ALL, BorderLineStyle.THIN);
- wcf_table.setVerticalAlignment(VerticalAlignment.CENTRE);
- wcf_table.setAlignment(Alignment.CENTRE);
- wcf_table.setBackground(Colour.GRAY_25);
- wcf_table.setWrap( true );
-
- sheet.mergeCells( 0 ,0 , 5 , 0 );
- sheet.addCell( new Label(0 , 0 , " 这里是大标题,自定义格式 " ,
- wcf_title));