當(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
          主站蜘蛛池模板: 祁门县| 饶河县| 隆回县| 邢台县| 赤水市| 固始县| 融水| 东辽县| 濮阳县| 项城市| 开封县| 洪江市| 孝昌县| 乐山市| 黑水县| 新乡县| 东台市| 内丘县| 多伦县| 谢通门县| 灵武市| 民县| 永吉县| 遵义市| 集安市| 筠连县| 乌拉特后旗| 乳山市| 蒙自县| 铜梁县| 抚顺县| 双峰县| 财经| 奉化市| 舞钢市| 北海市| 永仁县| 定边县| 香格里拉县| 衢州市| 慈溪市|