Package org.apache.poi.hssf.usermodel

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


        + ".xls", excelPath, wb, true);
  }

  private void createFormulaCell(HSSFRow row, short col, String formula,
      final HSSFCellStyle cellStyle) {
    HSSFCell cell = row.createCell(col);
    cell.setCellFormula(formula);
    if (cellStyle != null) {
      cell.setCellStyle(cellStyle);
    }
  }
View Full Code Here


    HSSFSheet sheet;

    sheet = wb.createSheet("sheet");
    int currentRow = 0;
    HSSFRow row;
    HSSFCell cell;

    CellStyle cellStyle = new CellStyle(wb, (short) headFontSize);

    // Overskrift
    if (heading != null && heading.length() != 0) {
      row = sheet.createRow((short) currentRow++);
      createCell(row, cellStyle.getHeadingStyle(), (short) 0, heading);
    }

    // Kolonneoverskrift
    row = sheet.createRow((short) currentRow++);
    int columnCount = table.getColumnCount();
    int rowCount = table.getRowCount();

    // Skriver ut kolonneoverskrift
    createColumnHeadings(row, cellStyle.getHeadingStyle(),
        table.getModel(), 0, columnCount, 0, notVisibleColumns);

    String groupValue = "";
    List<ExcelGroupSum> formulaCells = new ArrayList<ExcelGroupSum>();
    String groupSumValue = "";
    ExcelGroupSum currentExcelGroupSum = null;

    // Data
    int j;
    int k;
    int l = currentRow;
    // G�r gjennom alle rader og kolonner
    for (j = currentRow; j < rowCount + currentRow; j++) {
      // 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;
        }
        // henter grupperingsverdi og setter ny overskrift for
        // gruppering
        groupValue = (String) table.getValueAt(j - currentRow,
            groupColumn);
        row = sheet.createRow((short) l);
        createCell(row, cellStyle.getGroupStyle(), (short) 0,
            groupValue);
        sheet.addMergedRegion(new Region((short) l, (short) 0,
            (short) l,
            (short) (columnCount - notVisibleColumnsSize - 1)));
        l++;

      }
      setLabelInfo(labelInfo, infoString, j);

      row = sheet.createRow((short) l);
      l++;

      // g�r gjennom alle kolonner for rad
      for (k = 0; k < columnCount; k++) {
        // dersom kolonne skal v�re synlig
        if (notVisibleColumns == null || !notVisibleColumns.contains(k)) {
          // dersom kolonnebredde er satt
          if (colSize != null) {
            Integer columnSize = colSize.get(k);
            if (columnSize != null) {
              sheet.setColumnWidth((short) k, columnSize
                  .shortValue());
            }
          }
          cell = row.createCell((short) k);
          // dersom celle har verdi
          if (table.getValueAt(j - currentRow, k) != 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);

              short dayColorIndex = DayEnum
                  .getDayColorIndex(groupSumValue);

              if (currentExcelGroupSum != null) {
                currentExcelGroupSum.setToRow((short) (l - 1));
                formulaCells.add(currentExcelGroupSum);
              }
              if (groupResultColumn != null) {
                currentExcelGroupSum = new ExcelGroupSum(
                    (short) l, row
                        .createCell(groupResultColumn
                            .shortValue()),
                    groupSumColumn.shortValue(),
                    dayColorIndex, wb.createCellStyle());
              }

            }
            cell.setCellStyle(cellStyle.createDayStyle(wrapText,
                groupSumValue));

            // dersom kolonne ikke er summeringskolonne
            if (groupResultColumn == null || k != groupResultColumn) {
              setCellValue(table, numberCols, currentRow, 0,
                  cell, j, k);
            }
            // dersom celle ikke har verdi settes den til tomstreng
            // for � f� med eventuell formatering
          } else {
            cell
                .setCellStyle(cellStyle.createDayStyle(false,
                    null));
            cell.setCellValue(new HSSFRichTextString(""));
          }
        }
      }
    }
    // setter siste grupperingssum dersom det finnes
View Full Code Here

    return header.toString();
  }

  private String getCellValue(final HSSFRow excelRow, final int column,
      final String stringFormat) {
    HSSFCell cell = excelRow.getCell((short) column);
    String value = null;
    if (cell != null) {
      if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
        if (stringFormat != null) {
          value = String.format(stringFormat, cell
              .getNumericCellValue());
        } else {
          value = String.valueOf(cell.getNumericCellValue());
        }
      } else {
        value = cell.getRichStringCellValue().getString();
      }
    }
    if (value != null && value.length() == 0) {
      value = null;
    }
View Full Code Here

  {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet(sheetName);
    // 创建第1行,也就是输出表头
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell;
    for (int i = 0; i < columnNames.length; i++)
    {
      cell = row.createCell(i);
      cell.setCellValue(new HSSFRichTextString(columnNames[i]));
    }
    // 下面是输出各行的数据
    for (int i = 0; i < list.size(); i++)
    {
      row = sheet.createRow(i + 1);
      Object o = list.get(i);
      for (int j = 0; j < columnPropterties.length; j++)
      {
        cell = row.createCell(j);
        Object obj = ReflectionUtils.invokeGetterMethod(o, columnPropterties[j]);
        cell.setCellValue(obj == null ? "" : obj.toString());
      }
    }
    return workbook;
  }
View Full Code Here

  {
    wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet(sheetName);
    // 创建第1行,也就是输出表头
    HSSFRow row = sheet.createRow(0);
    HSSFCell cell;
    for (int i = 0; i < columnNames.length; i++)
    {
      cell = row.createCell(i);
      cell.setCellValue(new HSSFRichTextString(columnNames[i]));
    }
    // 下面是输出各行的数据
    for (int i = 0; i < list.size(); i++)
    {
      row = sheet.createRow(i + 1);
      Object o = list.get(i);
      for (int j = 0; j < columnPropterties.length; j++)
      {
        cell = row.createCell(j);
        Object obj = ReflectionUtils.invokeGetterMethod(o, columnPropterties[j]);
        cell.setCellValue(obj == null ? "" : obj.toString());
      }
    }
    wb.write(out);
  }
View Full Code Here

    CellRangeAddress titleRange = new CellRangeAddress(0, 0, 0,
        setInfo.getFieldNames().get(sheetNum).length);
    sheets[sheetNum].addMergedRegion(titleRange);
    HSSFRow titleRow = sheets[sheetNum].createRow(0);
    titleRow.setHeight((short) 800);
    HSSFCell titleCell = titleRow.createCell(0);
    titleCell.setCellStyle(titleStyle);
    titleCell.setCellValue(setInfo.getTitles()[sheetNum]);
  }
View Full Code Here

    CellRangeAddress dateRange = new CellRangeAddress(1, 1, 0,
        setInfo.getFieldNames().get(sheetNum).length);
    sheets[sheetNum].addMergedRegion(dateRange);
    HSSFRow dateRow = sheets[sheetNum].createRow(1);
    dateRow.setHeight((short) 350);
    HSSFCell dateCell = dateRow.createCell(0);
    dateCell.setCellStyle(dateStyle);
    dateCell.setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
  }
View Full Code Here

  {
    // 表头
    HSSFRow headRow = sheets[sheetNum].createRow(2);
    headRow.setHeight((short) 350);
    // 序号列
    HSSFCell snCell = headRow.createCell(0);
    snCell.setCellStyle(headStyle);
    snCell.setCellValue("序号");
    // 列头名称
    for(int num = 1, len = setInfo.getHeadNames().get(sheetNum).length; num <= len; num++)
    {
      HSSFCell headCell = headRow.createCell(num);
      headCell.setCellStyle(headStyle);
      headCell.setCellValue(setInfo.getHeadNames().get(sheetNum)[num - 1]);
    }
  }
View Full Code Here

                            rownum = Short.MAX_VALUE; }

                            row = _sheet.createRow((int)rownum);
                        }

                        HSSFCell cell = row.getCell(colnum);

                        if (cell == null) {
                            //getLogger().debug("creating blank cell at "+rownum + "," +colnum);
                            cell = row.createCell(colnum,HSSFCell.CELL_TYPE_BLANK);
                            cell.setCellStyle((HSSFCellStyle)regions.get(region));
                        }
                    }

                }
            }
View Full Code Here

     * Tests reading a file containing this ptg.
     */
    public void testReading() throws Exception
    {
        HSSFWorkbook workbook = loadWorkbook("UnionPtg.xls");
        HSSFCell cell = workbook.getSheetAt(0).getRow(4).getCell((short) 2);
        assertEquals("Wrong cell value", 24.0, cell.getNumericCellValue(), 0.0);
        assertEquals("Wrong cell formula", "SUM(A1:B2,B2:C3)", cell.getCellFormula());
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.hssf.usermodel.HSSFCell

Copyright © 2018 www.massapicom. 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.