Esempio n. 1
0
  /**
   * 罫線スタイルの<b>CellStyle</b>を生成 1行のみ描画する
   *
   * @param workbook ワークブック
   * @param sheet シート
   * @param nRow 行
   * @param nColumn       列
   * @param isBold 太字フラグ
   * @param fontSize 文字サイズ
   * @param fontHeight 行高
   */
  public static void setCellStyleForLabel(
      XSSFWorkbook workbook,
      XSSFSheet sheet,
      int nRow,
      int nColumn,
      boolean isBold,
      short fontSize,
      float fontHeight) {
    assert sheet != null;

    // style設定
    XSSFCellStyle style = workbook.createCellStyle();
    XSSFFont font = workbook.createFont();
    if (isBold) {
      font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD); // 文字太字
    }
    font.setFontHeightInPoints((short) fontSize); // 文字サイズ
    font.setFontName(DEFAULT_FONT_NAME);
    style.setFont(font); // 文字太字 と 文字サイズ

    style.setAlignment(CellStyle.ALIGN_GENERAL); // 水平方向の標準
    style.setVerticalAlignment(CellStyle.VERTICAL_TOP); // 垂直方向の上詰め
    style.setWrapText(true); // 折り返して全体を表示する

    // セルに罫線を描画
    XSSFRow row = getRowAnyway(sheet, nRow);
    XSSFCell cell = getCellAnyway(row, nColumn);
    cell.setCellStyle(style);
    row.setHeightInPoints(fontHeight); // 行高設定
  }
Esempio n. 2
0
 /**
  * 罫線スタイルの<b>CellStyle</b>を生成
  *
  * @param workbook ワークブック
  * @return <b>CellStyle</b>
  */
 public static XSSFCellStyle createTableDataCellStyle(XSSFWorkbook workbook) {
   XSSFCellStyle style = workbook.createCellStyle();
   style.setBorderTop(XSSFCellStyle.BORDER_THIN);
   style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
   style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
   style.setBorderRight(XSSFCellStyle.BORDER_THIN);
   return style;
 }
Esempio n. 3
0
 /**
  * デフォルトのセルスタイルを作成
  *
  * @param workbook ワークブック
  * @param bold 太字設定フラグ
  * @param centering センタリングフラグ
  * @param fontSize フォントサイズ
  * @return <b>CellStyle</b>
  */
 public static XSSFCellStyle createDefaultCellStyle(
     XSSFWorkbook workbook, boolean bold, boolean centering, int fontSize) {
   XSSFFont font = workbook.createFont();
   if (bold) {
     font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
   }
   font.setFontHeightInPoints((short) fontSize);
   font.setFontName(DEFAULT_FONT_NAME);
   XSSFCellStyle style = workbook.createCellStyle();
   style.setFont(font);
   if (centering) {
     style.setAlignment(CellStyle.ALIGN_CENTER_SELECTION);
   }
   return style;
 }
Esempio n. 4
0
 /**
  * 上線は太線のセル行を探す
  *
  * @param nRow 行データ
  * @return 有効列数
  */
 public static int getRowForBold(XSSFSheet sheet, int nRow, int pageRowNum) {
   int nRowIndex = nRow;
   for (nRowIndex = nRow; nRowIndex > (nRow - pageRowNum); nRow--) {
     XSSFRow row = OoxmlUtil.getRowAnyway(sheet, nRow);
     if (row != null) {
       XSSFCell cell = row.getCell(0);
       XSSFCellStyle styletmp = cell.getCellStyle();
       short borderTopnum = styletmp.getBorderTop();
       short borderBold = XSSFCellStyle.BORDER_MEDIUM;
       if (styletmp.getBorderTop() == (XSSFCellStyle.BORDER_MEDIUM)) {
         break;
       }
     }
   }
   return nRowIndex;
 }
Esempio n. 5
0
 /**
  * ハイパーリンクの設定
  *
  * @param sheet シート
  * @param nRow 対象行番号
  * @param nColumn 対象列番号
  * @param value ハイパーリンクテキスト
  * @param url ハイパーリンク先URL
  */
 public static void setHyperLink(
     XSSFSheet sheet, int nRow, int nColumn, String value, String url) {
   assert sheet != null;
   XSSFWorkbook workbook = sheet.getWorkbook();
   CreationHelper helper = workbook.getCreationHelper();
   Hyperlink hyperlink = helper.createHyperlink(Hyperlink.LINK_URL);
   hyperlink.setAddress(url);
   XSSFRow row = getRowAnyway(sheet, nRow);
   XSSFCell cell = getCellAnyway(row, nColumn);
   cell.setCellValue(value);
   cell.setHyperlink(hyperlink);
   // ハイパーリンクテキストの装飾
   XSSFFont font = workbook.createFont();
   XSSFCellStyle style = workbook.createCellStyle();
   // font.setColor(new XSSFColor(new Color(0, 0, 255)));
   font.setUnderline(XSSFFont.U_SINGLE);
   style.setFont(font);
   cell.setCellStyle(style);
 }
Esempio n. 6
0
 /**
  * 罫線スタイルの<b>CellStyle</b>を生成
  *
  * @param workbook ワークブック
  * @param backgroundColor 背景色
  * @return <b>CellStyle</b>
  */
 public static XSSFCellStyle createTableDataCellStyle(
     XSSFWorkbook workbook, Color backgroundColor) {
   XSSFCellStyle style = workbook.createCellStyle();
   style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); // 必ずsetFillForegroundColorの直前に記述すること
   style.setFillForegroundColor(new XSSFColor(backgroundColor));
   style.setBorderTop(XSSFCellStyle.BORDER_THIN);
   style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
   style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
   style.setBorderRight(XSSFCellStyle.BORDER_THIN);
   return style;
 }
Esempio n. 7
0
 /**
  * デフォルトのテーブルヘッダースタイルを作成
  *
  * @param workbook ワークブック
  * @param bold 太字設定フラグ
  * @param fontSize フォントサイズ
  * @param backgroundColor 背景色
  * @return <b>CellStyle</b>
  */
 public static XSSFCellStyle createDefaultTableHeaderCellStyle(
     XSSFWorkbook workbook, boolean bold, boolean center, int fontSize, Color backgroundColor) {
   XSSFFont font = workbook.createFont();
   if (bold) {
     font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
   }
   font.setFontHeightInPoints((short) fontSize);
   font.setFontName(DEFAULT_FONT_NAME);
   XSSFCellStyle style = workbook.createCellStyle();
   if (center) {
     style.setAlignment(XSSFCellStyle.ALIGN_CENTER);
   }
   style.setFont(font);
   style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); // 必ずsetFillForegroundColorの直前に記述すること
   style.setFillForegroundColor(new XSSFColor(backgroundColor));
   style.setBorderTop(XSSFCellStyle.BORDER_THIN);
   style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
   style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
   style.setBorderRight(XSSFCellStyle.BORDER_THIN);
   return style;
 }
Esempio n. 8
0
  /**
   * 罫線スタイルの<b>CellStyle</b>を生成
   *
   * @param workbook ワークブック
   * @param backgroundColor 背景色
   * @return <b>CellStyle</b>
   */
  public static XSSFCellStyle createTableDataCellStyle(
      XSSFWorkbook workbook,
      boolean isTop,
      boolean isBottom,
      boolean isLeft,
      boolean isRight,
      Color backgroundColor,
      short fontSize,
      boolean bold) {
    XSSFCellStyle style = workbook.createCellStyle();
    style.setFillPattern(XSSFCellStyle.SOLID_FOREGROUND); // 必ずsetFillForegroundColorの直前に記述すること
    style.setFillForegroundColor(new XSSFColor(backgroundColor));
    style.setAlignment(CellStyle.ALIGN_LEFT); // 水平方法の位置
    style.setVerticalAlignment(CellStyle.VERTICAL_TOP);
    style.setWrapText(true); // 折り返して全体を表示する
    //        style.setShrinkToFit(true);//縮小して全体を表示する

    // 文字サイズ設定
    XSSFFont font = workbook.createFont();
    font.setFontHeightInPoints(fontSize);
    if (bold) {
      font.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);
    }
    style.setFont(font);

    if (isTop) {
      style.setBorderTop(XSSFCellStyle.BORDER_MEDIUM);
    } else {
      style.setBorderTop(XSSFCellStyle.BORDER_THIN);
    }
    if (isBottom) {
      style.setBorderBottom(XSSFCellStyle.BORDER_MEDIUM);
    } else {
      style.setBorderBottom(XSSFCellStyle.BORDER_THIN);
    }
    if (isLeft) {
      style.setBorderLeft(XSSFCellStyle.BORDER_MEDIUM);
    } else {
      style.setBorderLeft(XSSFCellStyle.BORDER_THIN);
    }
    if (isRight) {
      style.setBorderRight(XSSFCellStyle.BORDER_MEDIUM);
    } else {
      style.setBorderRight(XSSFCellStyle.BORDER_THIN);
    }
    return style;
  }