Ejemplo n.º 1
0
 /**
  * 指定した行番号の<b>XSSFRow</b>を取得する。有効範囲外の行の場合は新規作成する。
  *
  * @param sheet <b>XSSFSheet</b>
  * @param nRow 取得したい行の行番号
  * @return <b>XSSFRow</b>
  */
 public static XSSFRow getRowAnyway(XSSFSheet sheet, int nRow) {
   assert sheet != null;
   XSSFRow row = sheet.getRow(nRow);
   if (row == null) {
     row = sheet.createRow(nRow);
   }
   return row;
 }
Ejemplo n.º 2
0
 /**
  * 列方向のセルの値を合算する
  *
  * @param sheet 編集対象シート
  * @param nColumn 行番号
  * @param nStartRow 開始列番号
  * @param nEndRow 終了列番号
  * @return 合算値
  */
 public static int sumColumn(XSSFSheet sheet, int nColumn, int nStartRow, int nEndRow) {
   int sum = 0;
   for (int nIndex = nStartRow; nIndex <= nEndRow; nIndex++) {
     XSSFRow row = sheet.getRow(nIndex);
     assert row != null;
     XSSFCell cell = row.getCell(nColumn);
     assert cell != null;
     if (cell.getCellType() == XSSFCell.CELL_TYPE_NUMERIC) {
       sum += cell.getNumericCellValue();
     }
   }
   return sum;
 }
Ejemplo n.º 3
0
 /**
  * 指定セルの削除
  *
  * @param sheet シート
  * @param startRow 開始行番号
  * @param endRow 終了行番号
  * @param startColumn 開始列番号
  * @param endColumn 終了列番号
  */
 public static void removeCell(
     XSSFSheet sheet, int startRow, int endRow, int startColumn, int endColumn) {
   assert sheet != null;
   for (int nRow = startRow; nRow <= endRow; nRow++) {
     XSSFRow row = sheet.getRow(nRow);
     if (row != null) {
       for (int nColumn = startColumn; nColumn <= endColumn; nColumn++) {
         XSSFCell cell = row.getCell(nColumn);
         if (cell != null) {
           row.removeCell(cell);
         }
       }
     }
   }
 }