Examples of HSSFCell


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

public class ExcelReaderTest {

  public void testReadCell() throws Exception {
    FileInputStream in = new FileInputStream("src/test/resources/date.xls");
    HSSFWorkbook wb = new HSSFWorkbook(in);
    HSSFCell dateCell = wb.getSheetAt(0).getRow(0).getCell(0);
    HSSFCell dateTimeCell = wb.getSheetAt(0).getRow(0).getCell(1);
    Object value = ExcelItemReader.getCellValue(dateCell);
    Assert.assertTrue(value instanceof Date);
    Object value2 = ExcelItemReader.getCellValue(dateTimeCell);
    Assert.assertTrue(value2 instanceof Date);
    in.close();
View Full Code Here

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

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

  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

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

    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

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

        {
          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

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

        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

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

           
            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

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

        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

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

        // 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

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

    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
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.