Package org.apache.poi.hssf.usermodel

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


   */
  public HSSFWorkbook toExcel(HSSFWorkbook wb, String sheetName, Collection<Object[]> datas,
      String propertyShowKeys) throws Exception {
    HSSFSheet sheet = wb.createSheet(sheetName);
    HSSFRow row = null;
    HSSFCell cell = null;

    /** **************** 取得传入的list列名称和显示名称 ********** */
    String[] pShowKeys = Tokenizer2StringArray(propertyShowKeys, ",");
    // 创建�?行(标题)
    row = sheet.createRow(0); // 建立新行
    // 显示标题列名
    for (int i = 0; i < pShowKeys.length; i++) {
      cell = row.createCell(i); // 建立新cell
      // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
      cell.setCellValue(new HSSFRichTextString(pShowKeys[i]));
    }
    // 逐行取数
    int rowId = 1;// 数据行号(从2行开始填充数�?)
    for (Iterator<Object[]> iter = datas.iterator(); iter.hasNext(); rowId++) {
      row = sheet.createRow(rowId); // 建立新行
      Object[] objs = iter.next();
      // 生成每一�?
      for (int j = 0; j < objs.length; j++) {
        cell = row.createCell(j); // 建立新cell
        // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
        cell.setCellValue(new HSSFRichTextString((objs[j] == null) ? "" : objs[j].toString()));
      }
    }
    return wb;
  }
View Full Code Here


  public <T extends Object> HSSFWorkbook object2Excel(HSSFWorkbook wb, String sheetName,
      Collection<T> list, String propertyKeys, String propertyShowKeys, PropertyExtractor exporter)
      throws Exception {
    HSSFSheet sheet = wb.createSheet(sheetName);
    HSSFRow row = null;
    HSSFCell cell = null;
    Object cellVal = null;

    /** **************** 取得传入的list列名称和显示名称 ********** */
    String[] pKeys = Tokenizer2StringArray(propertyKeys, ",");
    String[] pShowKeys = Tokenizer2StringArray(propertyShowKeys, ",");
    /** *************** insert data to excel*************** */
    // 创建(标题)
    row = sheet.createRow(0); // 建立新行
    // 显示标题列名�?
    for (int i = 0; i < pShowKeys.length; i++) {
      cell = row.createCell(i); // 建立新cell
      // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
      cell.setCellValue(new HSSFRichTextString(pShowKeys[i]));
    }
    // 逐行取数�?
    int rowId = 1;// 数据行号(从�?2行开始填充数�?)
    for (Iterator<T> iter = list.iterator(); iter.hasNext(); rowId++) {
      row = sheet.createRow(rowId); // 建立新行
      T obj = iter.next();
      // 生成每一
      for (int i = 0; i < pKeys.length; i++) {
        cell = row.createCell(i); // 建立新cell
        cellVal = exporter.getPropertyValue(obj, pKeys[i]);
        // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
        String cellValue = "";
        if (null != cellVal) {
          cellValue = cellVal.toString();
        }
        if (cellVal instanceof Float) {
          cellValue = numberformat.format(cellVal);
        }
        cell.setCellValue(new HSSFRichTextString(cellValue));
      }
    }
    return wb;
  }
View Full Code Here

    row.setHeightInPoints(lastRowHeight);
  }

  protected void setCell(JRExporterGridCell gridCell, int colIndex, int rowIndex)
  {
    HSSFCell emptyCell = row.getCell(colIndex);
    if (emptyCell == null)
    {
      emptyCell = row.createCell(colIndex);
      emptyCell.setCellStyle(emptyCellStyle);
    }
  }
View Full Code Here

        {
          spanRow = sheet.createRow(rowIndex + i);
        }
        for(int j = 0; j < gridCell.getColSpan(); j++)
        {
          HSSFCell spanCell = spanRow.getCell((colIndex + j));
          if (spanCell == null)
          {
            spanCell = spanRow.createCell((colIndex + j));
          }
          spanCell.setCellStyle(cellStyle);
        }
      }
    }
  }
View Full Code Here

        if (sheet != null) {
          for (int rowNumber = sheet.getFirstRowNum(); rowNumber <= sheet.getLastRowNum(); rowNumber++) {
            HSSFRow row = sheet.getRow(rowNumber);
            if (row != null) {
              for (int cellNumber = row.getFirstCellNum(); cellNumber <= row.getLastCellNum(); cellNumber++) {
                HSSFCell cell = row.getCell(cellNumber);
                if (cell != null) {
                  // if (cell.getCellStyle().equals(HSSFCell.CELL_TYPE_NUMERIC))
                  if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
                    content.append(cell.getStringCellValue()).append(' ');
                  }
                } else {
                  // throw new DocumentException();
                  cellNullCounter++;
                }
View Full Code Here

           
            Ref3DPtg ptg3D = (Ref3DPtg)ptg;
           
            HSSFSheet sheet = _workbook.getSheetAt(ptg3D.getExternSheetIndex() + 1 );     
            HSSFRow row     = sheet.getRow(ptg3D.getRow())
            HSSFCell cell   = row.getCell(ptg3D.getColumn());
           
            _currentSheetListener.newCell( formulaRec.getRow( ),
                    formulaRec.getColumn( ),
                                       "" + cell.getStringCellValue() );
                   
        }
    }
View Full Code Here

        for ( int i = 0; i <= sheet.getLastRowNum(); i++ )
        {
            HSSFRow row = sheet.getRow( i );
            for ( short j = 0; row != null && j <= row.getLastCellNum(); j++ )
            {
                HSSFCell cell = row.getCell( j );
                if ( cell != null && cell.getCellType() == HSSFCell.CELL_TYPE_STRING )
                {
                    String value = cell.getStringCellValue();

                    if ( ( short ) ( value.length() * 256 * 1.1 ) > sheet.getColumnWidth( j ) )
                    {
                        sheet.setColumnWidth( j, ( short ) ( value.length() * 256 * 1.1 ) );
                    }
View Full Code Here

        // output attributes
        HSSFRow row = sheet.createRow( sheet.getLastRowNum() + 1 );
        if ( exportDn )
        {
            HSSFCell cell = row.createCell( ( short ) 0 );
            cell.setEncoding( HSSFCell.ENCODING_UTF_16 );
            cell.setCellValue( record.getDnLine().getValueAsString() );
        }
        for ( String attributeName : attributeMap.keySet() )
        {
            String value = ( String ) attributeMap.get( attributeName );

            if ( !headerRowAttributeNameMap.containsKey( attributeName ) )
            {
                short cellNum = ( short ) headerRowAttributeNameMap.size();
                headerRowAttributeNameMap.put( attributeName, new Short( cellNum ) );
                HSSFCell cell = headerRow.createCell( cellNum );
                cell.setEncoding( HSSFCell.ENCODING_UTF_16 );
                cell.setCellValue( attributeName );
            }

            if ( headerRowAttributeNameMap.containsKey( attributeName ) )
            {
                short cellNum = ( ( Short ) headerRowAttributeNameMap.get( attributeName ) ).shortValue();
                HSSFCell cell = row.createCell( cellNum );
                cell.setEncoding( HSSFCell.ENCODING_UTF_16 );
                cell.setCellValue( value );
            }
        }

        // for (int i = 0; i < attributes.length; i++) {
        //     
View Full Code Here

    private HSSFCell getCell(HSSFSheet sheet, int rownum, int col) {
        HSSFRow row = sheet.getRow(rownum);
        if (row == null) {
            row = sheet.createRow(rownum);
        }
        HSSFCell cell = row.getCell(col);
        if (cell == null) {
            cell = row.createCell(col);
        }
        cell.setCellStyle(commonStyle);
        return cell;
    }
View Full Code Here

        testConditionSheet = workbook.getSheet(Constants.TEST_CONDITION_SHEET_NAME);
        if (testConditionSheet == null) {
            throw new IOException("Excelファイル: " + filename + "にテスト条件データのシートが存在しません");
        }

        HSSFCell tableNameCell = getCell(testConditionSheet,
                ConditionSheetItem.TABLE_NAME.getRow(),
                ConditionSheetItem.TABLE_NAME.getCol() + 1);
        tablename = tableNameCell.getStringCellValue();
        if (tablename == null || tablename.length() == 0) {
            throw new IOException("Excelファイル: " + filename + "にテーブル名が定義されていません");
        }

        HSSFCell rowMatchingConditionCell = getCell(testConditionSheet,
                ConditionSheetItem.ROW_MATCHING_CONDITION.getRow(),
                ConditionSheetItem.ROW_MATCHING_CONDITION.getCol() + 1);
        String rowMatchingConditionStr = rowMatchingConditionCell.getStringCellValue();
        if (rowMatchingConditionStr == null || rowMatchingConditionStr.length() == 0) {
            throw new IOException("Excelファイル: " + filename + "にテーブルの比較条件が定義されていません");
        }
        rowMatchingCondition = RowMatchingCondition.getConditonByJapanseName(rowMatchingConditionStr);
        if (rowMatchingCondition == null) {
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.