Examples of HSSFRow


Examples of com.dotcms.repackage.org.apache.poi.hssf.usermodel.HSSFRow

        HSSFSheet sheet = workbook.getSheetAt(i);

        Iterator rowIterator = sheet.rowIterator();

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

          Iterator cellIterator = row.cellIterator();

          while (cellIterator.hasNext()) {
            HSSFCell cell = (HSSFCell)cellIterator.next();

            String cellStringValue = null;
View Full Code Here

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

                 int rowCount2 = sheet2.getLastRowNum();
                 // check if rows are the same for both books
                 if(rowCount1 == rowCount2) {
                   // iterate through the rows
                   for(int j=sheet1.getFirstRowNum();j<=rowCount1;j++) {
                     HSSFRow row1 = sheet1.getRow(j);
                     HSSFRow row2 = sheet2.getRow(j);
                     // check if the rows are not null
                     if(row1 != null && row2 != null) {
                         Iterator it1 = row1.cellIterator();
                         Iterator it2 = row2.cellIterator();
                         while(it1.hasNext() && it2.hasNext()) {
                             HSSFCell cell1 = (HSSFCell) it1.next();
                             HSSFCell cell2 = (HSSFCell) it2.next();
                             if(cell1 != null && cell2 != null) {
                               HSSFCellStyle cell1Style = cell1.getCellStyle();
View Full Code Here

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

    // iterate through the rows
    int rowCount1 = sheet1.getLastRowNum();
    for (int j = sheet1.getFirstRowNum(); j <= rowCount1; j++)
    {
      HSSFRow row1 = sheet1.getRow(j);
      HSSFRow row2 = sheet2.getRow(j);
      // check if the rows are not null
      if (row1 == null && row2 == null)
      {
        continue;
      }
     
      if (row1 == null || row2 == null)
      {
        String dataToWrite = "Sheet #" + sheetNumber + "Row # " + j + "has a different data.File 1 Cell has " + row1 + "Whereas File2 has " + row2 + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
        outputStream.write(dataToWrite.getBytes());
        return false;
      }

      Iterator it1 = row1.cellIterator();
      Iterator it2 = row2.cellIterator();
      while (it1.hasNext() && it2.hasNext())
      {
        HSSFCell cell1 = (HSSFCell) it1.next();
        HSSFCell cell2 = (HSSFCell) it2.next();
        if (cell1 == null || cell2 == null)
View Full Code Here

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

 
  // ----------------------------------------------------------

  public void parseSheet(HSSFSheet oSheet, String sFileDescriptor) {
    HSSFCell oCel;
    HSSFRow oRow = oSheet.getRow(0);
    int iRow;
    char cDelim;
    String[] aFileDescriptor;
    int iFileDescLen;
   
    if (isVoid(sFileDescriptor)) {
      iRow = 1;
      sFileDescriptor = "";
      short iCel = (short) 0;
    oCel = oRow.getCell(iCel);
    while (oCel!=null) {
      if (isVoid(oCel.getStringCellValue())) break;
      sFileDescriptor += (sFileDescriptor.length()==0 ? "" : "\t") + oCel.getStringCellValue();
      oCel = oRow.getCell(++iCel);
    } // wend
    } else {
      iRow = 1;
      aFileDescriptor = Gadgets.split(sFileDescriptor, extractDelimiter(sFileDescriptor));
      iFileDescLen = aFileDescriptor.length;
      for (int c=0; c<iFileDescLen; c++) {
        oCel = oRow.getCell(c);
        if (null==oCel) {
          iRow = 0;
          break;
        } else if (!aFileDescriptor[c].equalsIgnoreCase(oCel.getStringCellValue())) {
          iRow = 0;
          break;         
        }
      } //next
    } // fi
    cDelim = extractDelimiter(sFileDescriptor);
    aFileDescriptor = Gadgets.split(sFileDescriptor, cDelim);
    iFileDescLen = aFileDescriptor.length;
    StringBuffer oData = new StringBuffer();
  while (!isEmptyRow(oSheet.getRow(iRow),iFileDescLen)){
    oRow = oSheet.getRow(iRow);
    if (oRow.getCell(0)!=null)
      oData.append(oRow.getCell(0).getStringCellValue());
    for (int c=1; c<iFileDescLen; c++) {
      oData.append(cDelim);
      if (oRow.getCell(c)!=null)
        oData.append(oRow.getCell(c).getStringCellValue());
    } // next
    oData.append((char) 10);
    iRow++;
  } // wend
  parseData(oData.toString().toCharArray(), sFileDescriptor);
View Full Code Here

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

  {
   StringBuffer sb = new StringBuffer();

   //*-- scan the rows from top to bottom
   for (int i = cSheet.getFirstRowNum(); i <= cSheet.getLastRowNum(); i++)
   { HSSFRow cRow = cSheet.getRow(i);
     if (cRow == null) continue;      //*-- skip empty rows

     //*-- for every row, scan each cell from left to right
     for (short j = cRow.getFirstCellNum(); j <= cRow.getLastCellNum(); j++)
     { HSSFCell cCell = cRow.getCell(j);

     if (cCell == null) continue//*-- skip empty cells
     if (cCell.getCellType() == HSSFCell.CELL_TYPE_STRING)
      { String cellValue = cCell.getStringCellValue();
        if (cellValue != null) { sb.append(" "); sb.append(cellValue); }
View Full Code Here

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

      sheet = workbook.createSheet();
    }
    title = data;
    index = 0;
    writeItem(data);
    HSSFRow titleRow = sheet.getRow(index);
    HSSFCellStyle titleStyle = getTitleStyle();
    for (int i = 0; i < titleRow.getLastCellNum(); i++) {
      titleRow.getCell(i).setCellStyle(titleStyle);
    }
    index++;
  }
View Full Code Here

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

  public String getFormat() {
    return TransferFormats.XLS;
  }

  protected void writeItem(Object datas) {
    HSSFRow row = sheet.createRow(index); // 建立新行
    if (datas != null) {
      if (datas.getClass().isArray()) {
        Object[] values = (Object[]) datas;
        for (int i = 0; i < values.length; i++) {
          HSSFCell cell = row.createCell(i);
          if (values[i] instanceof Number) {
            cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
            cell.setCellValue(((Number) values[i]).doubleValue());
          } else if (values[i] instanceof java.sql.Date) {
            cell.setCellValue((Date) values[i]);
            cell.setCellStyle(getDateStyle());
          } else if (values[i] instanceof java.util.Date) {
            cell.setCellValue((Date) values[i]);
            cell.setCellStyle(getTimeStyle());
          } else if (values[i] instanceof Calendar) {
            cell.setCellValue((Calendar) values[i]);
            cell.setCellStyle(getTimeStyle());
          } else {
            cell.setCellValue(new HSSFRichTextString((values[i] == null) ? "" : values[i]
                .toString()));
          }
        }
      } else {
        HSSFCell cell = row.createCell(0);
        // cell.setEncoding(HSSFCell.ENCODING_UTF_16);
        if (datas instanceof Number) {
          cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);
        }
        cell.setCellValue(new HSSFRichTextString(datas.toString()));
View Full Code Here

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

   * @param sheet
   * @param rowIndex
   * @return
   */
  protected String[] readLine(HSSFSheet sheet, int rowIndex) {
    HSSFRow row = sheet.getRow(rowIndex);
    logger.debug("values count:{}", row.getLastCellNum());
    List<String> attrList = CollectUtils.newArrayList();
    for (int i = 0; i < row.getLastCellNum(); i++) {
      HSSFCell cell = row.getCell(i);
      if (null != cell) {
        String attr = cell.getRichStringCellValue().getString();
        if (StringUtils.isEmpty(attr)) {
          break;
        } else {
View Full Code Here

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

  }

  public Object read() {
    HSSFSheet sheet = workbook.getSheetAt(sheetNum);
    if (indexInSheet > sheet.getLastRowNum()) { return null; }
    HSSFRow row = sheet.getRow(indexInSheet);
    indexInSheet++;
    // 如果是个空行,返回空记录
    if (row == null) {
      return new Object[attrCount];
    } else {
      Object[] values = new Object[((attrCount != 0) ? attrCount : row.getLastCellNum())];
      for (int k = 0; k < values.length; k++) {
        values[k] = getCellValue(row.getCell(k));
      }
      return values;
    }
  }
View Full Code Here

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

  public static void main(String[] args) throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet("new sheet");

    // Create a row and put some cells in it. Rows are 0 based.
    HSSFRow row = sheet.createRow(0);

    // Create a cell and put a date value in it. The first cell is not
    // styled as a date.
    HSSFCell cell = row.createCell(0);
    cell.setCellValue(new Date());

    // we style the second cell as a date (and time). It is important to
    // create a new cell style from the workbook
    // otherwise you can end up modifying the built in style and effecting
    // not only this cell but other cells.
    HSSFCellStyle cellStyle = wb.createCellStyle();
    DataFormat df = wb.createDataFormat();
    // cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
    cellStyle.setDataFormat(df.getFormat("YYYY-MM-DD HH:MM:SS"));
    cell = row.createCell(1);
    cell.setCellValue(new Date());
    cell.setCellStyle(cellStyle);
    // Write the output to a file
    FileOutputStream fileOut = new FileOutputStream("src/test/resources/workbook.xls");
    wb.write(fileOut);
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.