當柳上原的風吹向天際的時候...

          真正的快樂來源于創造

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

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

          2.設置列寬
          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.設置缺省行高
          sheet.setDefaultRowHeight((short)360);

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

          5.給單元格設置字體及下邊框
          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.給單元格設置背景色
          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 何楊 閱讀(344) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 洛扎县| 丹东市| 泾川县| 灵宝市| 冷水江市| 庄河市| 驻马店市| 鄂托克旗| 华亭县| 汝阳县| 寻乌县| 株洲市| 嵊泗县| 广昌县| 东方市| 清丰县| 衢州市| 奉化市| 邯郸县| 富川| 碌曲县| 安阳县| 枣强县| 武隆县| 石城县| 张掖市| 丰县| 龙陵县| 江西省| 巧家县| 宜兰县| 永泰县| 龙山县| 合阳县| 奈曼旗| 交城县| 砀山县| 德化县| 灵川县| 平南县| 雷州市|