Examples of HSSFCell


Examples of org.apache.poi.hssf.usermodel.HSSFCell

     * @param col
     * @return
     */
    private HSSFCell getCell(HSSFSheet sheet, int rownum, int col) {
        HSSFRow row = sheet.getRow(rownum);
        HSSFCell cell = row.getCell(col);
        return cell;
    }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFCell

        HSSFSheet sheet = workbook.createSheet(sheetName);

        // カラム名を設定
        HSSFRow row = sheet.createRow(0);
        for (int i = 0; i < columnInfos.length; i++) {
            HSSFCell cell = row.createCell(i);
            cell.setCellValue(columnInfos[i].getColumnName());
            cell.setCellStyle(titleStyle);
        }

        // DBのデータを設定
        PreparedStatement ps = null;
        ResultSet rs = null;

        String sql =
            "SELECT * FROM "
            + databaseName + "." + tableName
            + " limit 0, " + Constants.MAX_ROWS;
        try {
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()) {
                row = sheet.createRow(row.getRowNum() + 1);
                for (int i = 0; i < columnInfos.length; i++) {
                    ColumnInfo info = columnInfos[i];
                    HSSFCell cell = row.createCell(i);
                    cell.setCellStyle(commonStyle);
                    switch (info.getDataType()) {
                    case CHAR:
                    case VARCHAR:
                        String str = rs.getString(info.getColumnName());
                        if (!rs.wasNull()) {
                            cell.setCellValue(str);
                        }
                        break;
                    case DATE:
                        Date date = rs.getDate(info.getColumnName());
                        if (!rs.wasNull()) {
                            cell.setCellValue(new java.util.Date(date.getTime()));
                            cell.setCellStyle(dateStyle);
                        }
                        break;
                    case DATETIME:
                    case TIMESTAMP:
                        Timestamp ts = rs.getTimestamp(info.getColumnName());
                        if (!rs.wasNull()) {
                            cell.setCellValue(new java.util.Date(ts.getTime()));
                            cell.setCellStyle(dateTimeStyle);
                        }
                        break;
                    case DECIMAL:
                        BigDecimal decimal = rs.getBigDecimal(info.getColumnName());
                        if (!rs.wasNull()) {
                            cell.setCellValue(decimal.toPlainString());
                        }
                        break;
                    case TINY_INT:
                    case SMALL_INT:
                    case INT:
                    case LONG:
                        long value = rs.getLong(info.getColumnName());
                        if (!rs.wasNull()) {
                            cell.setCellValue(Long.toString(value));
                        }
                        break;
                    default:
                        assert false;
                        break;
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFCell

           
            // Create a row and put some cells in it. Rows are 0 based.
            HSSFRow row = sheet.createRow(currentRow);
           
            // Create a cell and put a value in it.
            HSSFCell cell = row.createCell((short)0);
            cell.setCellValue(s);

            currentRow++;
     }

   
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFCell

      for (int thisCellinRange = 0; thisCellinRange < crefs.length; thisCellinRange++) {
        HSSFSheet sheet = wb.getSheet(crefs[thisCellinRange]
            .getSheetName());
        HSSFRow r = sheet.getRow(crefs[thisCellinRange].getRow());

        HSSFCell thisExcelCell = null;
        if (r != null) {
          thisExcelCell = r.getCell(crefs[thisCellinRange].getCol());
          // extract the cell contents based on cell type etc.
        }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFCell

            .getSheetName());

        HSSFRow r = sheet.getRow(crefs[thisCellinRange].getRow());

        // Get the cell that is referred to
        HSSFCell excelCell = null;
        if (r != null) {
          excelCell = r.getCell(crefs[thisCellinRange].getCol());

          // Check that the range name is on our list
          String cellHandle = Range.getUniqueCellName(aNamedCell
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFCell

            HSSFRow headerRow = sheet.createRow(0);

            for (int columnIndex = 0; columnIndex < model.getColumnCount(); columnIndex++){
                String columnName = model.getColumnName(columnIndex);

                HSSFCell cell = headerRow.createCell(columnIndex);
                cell.setCellValue(columnName);

                HSSFCellStyle cellStyle = workbook.createCellStyle();
                HSSFFont tableHeadingFont = workbook.createFont();
                tableHeadingFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
                cellStyle.setFont(tableHeadingFont);
                cell.setCellStyle(cellStyle);
            }
        }

        CellStyleCache cellStyleCache = new CellStyleCache(workbook, model.getProject());

        for (short rowIndex = 0; rowIndex < model.getRowCount(); rowIndex++) {
            HSSFRow row = sheet.createRow(rowIndex + 1);
            for (int columnIndex = 0; columnIndex < model.getColumnCount(); columnIndex++){
                HSSFCell cell = row.createCell(columnIndex);
                Object value = model.getValue(rowIndex, columnIndex);
                if (value != null) {
                    if (value instanceof Number) {
                        Number number = (Number) value;
                        double doubleValue = number.doubleValue();
                        cell.setCellValue(doubleValue);
                        cell.setCellStyle(
                                doubleValue % 1 == 0 ?
                                        cellStyleCache.getIntegerStyle() :
                                        cellStyleCache.getNumberStyle());

                    } else if (value instanceof Date) {
                        Date date = (Date) value;
                        boolean hasTime = hasTimeComponent(date);
                        cell.setCellValue(date);
                        cell.setCellStyle(hasTime ?
                                cellStyleCache.getDatetimeStyle() :
                                cellStyleCache.getDateStyle());
                    } else {
                        cell.setCellValue(value.toString());
                    }
                }
            }
        }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFCell

                            while (rows.hasNext()) {
                                HSSFRow row = (HSSFRow) rows.next();

                                Iterator cells = row.cellIterator();
                                while (cells.hasNext()) {
                                    HSSFCell cell = (HSSFCell) cells.next();
                                    switch (cell.getCellType()) {
                                    case HSSFCell.CELL_TYPE_NUMERIC:
                                        String num = Double.toString(cell.getNumericCellValue()).trim();
                                        if (num.length() > 0) {
                                            writer.write(num + " ");
                                        }
                                        break;
                                    case HSSFCell.CELL_TYPE_STRING:
                                        String text = cell.getStringCellValue().trim();
                                        if (text.length() > 0) {
                                            writer.write(text + " ");
                                        }
                                        break;
                                    }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFCell

  }

  private static void createCell(final HSSFRow row,
      final HSSFCellStyle cellStyle, final short column,
      final String value) {
    HSSFCell cell;
    cell = row.createCell(column);
    cell.setCellValue(new HSSFRichTextString(value));
    if (cellStyle != null) {
      cell.setCellStyle(cellStyle);
    }
  }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFCell

  }

  private static void createCell(final HSSFRow row,
      final HSSFCellStyle cellStyle, final short column,
      final String value, final Double doubleValue) {
    HSSFCell cell;
    cell = row.createCell(column);
    if (doubleValue != null) {
      cell.setCellValue(doubleValue);
    } else {
      cell.setCellValue(new HSSFRichTextString(value));
    }
    if (cellStyle != null) {
      cell.setCellStyle(cellStyle);
    }
  }
View Full Code Here

Examples of org.apache.poi.hssf.usermodel.HSSFCell

    // det skal legges til en summeringsformel p� sluttet
    if (sumFormula != null) {
      sumFormula.setFromRow(l + 1);
    }
    HSSFCell cell;
    String groupValue = "";
    List<ExcelGroupSum> formulaCells = new ArrayList<ExcelGroupSum>();
    String groupSumValue = "";
    ExcelGroupSum currentExcelGroupSum = null;
    // G�r gjennom alle rader og kolonner
    for (j = currentRow; j < rowCount + currentRow; j++) {
      rowNumber++;
      // dersom data skal grupperes
      if (groupColumn != null
          && !table.getValueAt(j - currentRow, groupColumn).equals(
              groupValue)) {
        // setter forrige grupperingssum
        if (currentExcelGroupSum != null) {
          currentExcelGroupSum.setToRow((short) (l));
          formulaCells.add(currentExcelGroupSum);
          groupSumValue = "";
          currentExcelGroupSum = null;
          rowNumber = 1;
        }
        // henter grupperingsverdi og setter ny overskrift for
        // gruppering
        groupValue = (String) table.getValueAt(j - currentRow,
            groupColumn);
        row = excelSheet.createRow((short) l);

        createCell(row, cellStyle.getGroupStyle(),
            (short) (startCell - addedColumn), groupValue);
        excelSheet.addMergedRegion(new Region((short) l, (short) 0,
            (short) l, (short) (columnCount + addedColumn
                - notVisibleColumnsSize - 1)));
        l++;

      }
      setLabelInfo(labelInfo, infoString, j);
      row = excelSheet.createRow((short) l);
      l++;
      // dersom det skal skrives ut rad nummer
      if (writeRowNumber) {
        cell = row.createCell((short) (startCell - 1));
        cell.setCellValue(rowNumber);
      }
      // g�r gjennom alle kolonner for rad
      for (k = startCell; k < columnCount + startCell; k++) {
        // dersom kolonne skal v�re synlig
        if (notVisibleColumns == null
            || !notVisibleColumns.contains(k - startCell)) {
          setColumnSize(colSize, excelSheet, startCell, addedColumn,
              k);
          cell = row.createCell((short) k);
          // dersom celle har verdi
          if (table.getValueAt(j - currentRow, k - startCell) != null) {
            // dersom det er grupperingssum satt og den er ulik
            // forrige
            if (groupSumValueColumn != null
                && !table.getValueAt(j - currentRow,
                    groupSumValueColumn).equals(
                    groupSumValue)) {

              groupSumValue = (String) table.getValueAt(j
                  - currentRow, groupSumValueColumn);
              if (currentExcelGroupSum != null) {
                currentExcelGroupSum.setToRow((short) (l - 1));
                formulaCells.add(currentExcelGroupSum);
              }
              if (groupResultColumn != null
                  && groupSumColumn != null) {
                currentExcelGroupSum = new ExcelGroupSum(
                    (short) l,
                    row
                        .createCell((short) (groupResultColumn
                            .shortValue() + addedColumn)),
                    groupSumColumn.shortValue(),
                    DayEnum.getDayColorIndex(groupSumValue),
                    wb.createCellStyle());
              }
            }
            cell.setCellStyle(cellStyle.createDayStyle(false,
                groupSumValue));
            setCellValueForNotSumColumn(table, numberCols,
                groupResultColumn, currentRow, startCell, cell,
                j, k);
            // dersom celle ikke har verdi settes den til tomstreng
            // for � f� med eventuell formatering
          } else {
            cell
                .setCellStyle(cellStyle.getDayStyle(wrapText,
                    null));
            cell.setCellValue(new HSSFRichTextString(""));
          }
        }
      }
    }
    // det skal legges til en summeringsformel p� sluttet
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.