當(dāng)柳上原的風(fēng)吹向天際的時候...

          真正的快樂來源于創(chuàng)造

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            368 Posts :: 1 Stories :: 201 Comments :: 0 Trackbacks
          POI是Java對Office操作的常用工具包,網(wǎng)上資料有很多,但良莠不齊,臨時便找邊試容易耽誤時間,故收集一些常用操作在這里以便查閱.

          1.創(chuàng)建Sheet
          Sheet sheet = workbook.createSheet();
          workbook.setSheetName(0, "Sheet0");

          2.設(shè)置列寬
          static final int[] COLUMN_WIDTHS = new int[] { 4*3500, 2*3500, 5*3500,
                      2*3500, 3*3500, 3*3500, 3500, 3*3500, 2*3800, 2*3500};
          for (int colnum = 0; colnum < COLUMN_WIDTHS.length; colnum++) {
              sheet.setColumnWidth(colnum, COLUMN_WIDTHS[colnum]);
          }

          3.設(shè)置缺省行高
          sheet.setDefaultRowHeight((short)360);

          4.設(shè)置某一行行高
          Row rowFirst = sheet.createRow(0);
          rowFirst.setHeightInPoints(20.0f);

          5.給單元格設(shè)置字體及下邊框
          Cell cell00 = rowFirst.createCell(0);
          cell00.setCellValue("abc123");            

          HSSFFont fontAriel12Bold = workbook.createFont();
          fontAriel12Bold.setFontName("Arial");
          fontAriel12Bold.setFontHeightInPoints((short)12);
          fontAriel12Bold.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
          fontAriel12Bold.setColor(HSSFColor.RED.index);

          HSSFCellStyle cell00FontStyle = workbook.createCellStyle();
          cell00FontStyle.setBorderBottom(HSSFCellStyle.BORDER_THICK);
          cell00FontStyle.setFont(fontAriel12Bold);
          cell00.setCellStyle(cell00FontStyle);

          6.給單元格設(shè)置背景色
          HSSFCellStyle blueStyle = workbook.createCellStyle();
          blueStyle.setBorderTop(HSSFCellStyle.BORDER_THICK);
          blueStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
          blueStyle.setFillForegroundColor(HSSFColor.SKY_BLUE.index);
          blueStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
          Cell cell=row9.createCell(0);
          cell.setCellStyle(blueStyle);
          posted on 2012-12-14 17:45 何楊 閱讀(339) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 安溪县| 龙泉市| 嵊州市| 尤溪县| 如东县| 中西区| 开化县| 汽车| 琼海市| 灌云县| 仁怀市| 将乐县| 湘乡市| 贞丰县| 交城县| 旌德县| 广饶县| 名山县| 锡林浩特市| 彩票| 吉安市| 漯河市| 胶州市| 淳安县| 南昌县| 龙井市| 吴江市| 深州市| 迁安市| 沙雅县| 渝中区| 桐乡市| 平谷区| 临颍县| 彰化市| 大田县| 富宁县| 大港区| 新化县| 景宁| 鄂尔多斯市|