Package org.apache.poi.ss.usermodel

Examples of org.apache.poi.ss.usermodel.Row


          + "********************");
      int firstRow = sheet.getFirstRowNum();
      int lastRow = sheet.getLastRowNum();
      for (int i = firstRow; i <=lastRow; i++) {
        System.out.printf("%d", i + 1);
        Row row = sheet.getRow(i);
        if (row != null) {
          int firstCell = row.getFirstCellNum();
          int lastCell = row.getLastCellNum();
          for (int j = firstCell; j < lastCell; j++) {
            Cell cell = row.getCell(j);
            if (cell == null) {
              System.out.printf("\t\tnull");
            } else {
              if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
                System.out.printf("\t\t( )blank");
View Full Code Here


      int firstRowNum = sheet.getFirstRowNum();
      int lastRowNum = sheet.getLastRowNum();
      if (firstRowNum != lastRowNum) {
        return false;
      }else{
        Row row = sheet.getRow(firstRowNum);
        if(row!=null){
          int firstColNum = row.getFirstCellNum();
          int lastColNum = row.getLastCellNum();
          if(firstColNum!=lastColNum){
            return false;
          }
        }
      }
View Full Code Here

  public static void copySheets(Sheet newSheet, Sheet sheet, boolean copyStyle) {
    int maxColumnNum = 0;
    Map<Integer, CellStyle> styleMap = (copyStyle) ? new HashMap<Integer, CellStyle>()
        : null;
    for (int i = sheet.getFirstRowNum(); i <= sheet.getLastRowNum(); i++) {
      Row srcRow = sheet.getRow(i);
      Row destRow = newSheet.createRow(i);
      if (srcRow != null) {
        copyRow(sheet, newSheet, srcRow, destRow, styleMap);
        if (srcRow.getLastCellNum() > maxColumnNum) {
          maxColumnNum = srcRow.getLastCellNum();
        }
View Full Code Here

    int endRow = sheet.getLastRowNum();
    // System.out.println("start "+startRow);
    // System.out.println("end "+endRow);
    final List<List<String>> data = new ArrayList<List<String>>();
    for (int i = startRow; i <= endRow; i++) {
      Row row = sheet.getRow(i);
      if (row == null) {
        continue;
      }
      short startCell = row.getFirstCellNum();
      short endCell = row.getLastCellNum();
      for (short j = startCell; j <= endCell; j++) {
        Cell cell = row.getCell(j);
        String cellStringValue = null;
        if (cell != null) {
          cellStringValue = cell.getStringCellValue();
        }
        if (cellStringValue != null) {
View Full Code Here

       
        System.out.println("default column width:"+sheet.getDefaultColumnWidth());
        int firstRow = sheet.getFirstRowNum();
        int lastRow = sheet.getLastRowNum();
        for(int j=firstRow;j<lastRow;j++){
          Row row = sheet.getRow(j);
          if(row!=null){
            System.out.println("row height:"+row.getHeightInPoints());
            int firstColumn = row.getFirstCellNum();
            int lastColumn = row.getLastCellNum();
            for(int k=firstColumn;k<lastColumn;k++){
              System.out.printf("Row[%d] Column[%d] %d\n",j,k,ExcelUtility.widthUnits2Pixel(sheet.getColumnWidth(k)));
            }
          }else{
            System.out.printf("Row[%d] is null\n",j);
View Full Code Here

     */
    @Test
    public void bug47490() throws Exception {
       XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("GeneralFormatTests.xlsx");
       Sheet s = wb.getSheetAt(1);
       Row r;
       DataFormatter df = new DataFormatter();
      
       r = s.getRow(1);
       assertEquals(1.0, r.getCell(2).getNumericCellValue(), 0);
       assertEquals("General", r.getCell(2).getCellStyle().getDataFormatString());
       assertEquals("1", df.formatCellValue(r.getCell(2)));
       assertEquals("1", df.formatRawCellContents(1.0, -1, "@"));
       assertEquals("1", df.formatRawCellContents(1.0, -1, "General"));
             
       r = s.getRow(2);
       assertEquals(12.0, r.getCell(2).getNumericCellValue(), 0);
       assertEquals("General", r.getCell(2).getCellStyle().getDataFormatString());
       assertEquals("12", df.formatCellValue(r.getCell(2)));
       assertEquals("12", df.formatRawCellContents(12.0, -1, "@"));
       assertEquals("12", df.formatRawCellContents(12.0, -1, "General"));
      
       r = s.getRow(3);
       assertEquals(123.0, r.getCell(2).getNumericCellValue(), 0);
       assertEquals("General", r.getCell(2).getCellStyle().getDataFormatString());
       assertEquals("123", df.formatCellValue(r.getCell(2)));
       assertEquals("123", df.formatRawCellContents(123.0, -1, "@"));
       assertEquals("123", df.formatRawCellContents(123.0, -1, "General"));
    }
View Full Code Here

             new HSSFWorkbook(),
             new XSSFWorkbook()
       };
       for(Workbook wb : wbs) {
          Sheet s = wb.createSheet();
          Row r = s.createRow(0);
         
          // Setup
          Cell cn = r.createCell(0, Cell.CELL_TYPE_NUMERIC);
          cn.setCellValue(1.2);
          Cell cs = r.createCell(1, Cell.CELL_TYPE_STRING);
          cs.setCellValue("Testing");
         
          Cell cfn = r.createCell(2, Cell.CELL_TYPE_FORMULA);
          cfn.setCellFormula("A1")
          Cell cfs = r.createCell(3, Cell.CELL_TYPE_FORMULA);
          cfs.setCellFormula("B1");
         
          FormulaEvaluator fe = wb.getCreationHelper().createFormulaEvaluator();
          assertEquals(Cell.CELL_TYPE_NUMERIC, fe.evaluate(cfn).getCellType());
          assertEquals(Cell.CELL_TYPE_STRING, fe.evaluate(cfs).getCellType());
View Full Code Here

        Sheet sheet = wb.getSheetAt(0);


        // go through all formula cells
        for (int rInd = 2; rInd <= rowMax; rInd++) {
            Row row = sheet.getRow(rInd);

            for (int cInd = 1; cInd <= 12; cInd++) {
                Cell cell = row.getCell(cInd);
                String formula = cell.getCellFormula();
                CellReference ref = new CellReference(cell);

                //simulate correct answer
                String correct = "$A" + (rInd + 1) + "*" + columns[cInd] + "$2";
View Full Code Here

     
      assertSheetOrder(wb, "Sheet1");
     
      Sheet sheet = wb.getSheetAt(0);
      sheet.shiftRows(2, sheet.getLastRowNum(), 1, true, false);
      Row newRow = sheet.getRow(2);
      if (newRow == null) newRow = sheet.createRow(2);
      newRow.createCell(0).setCellValue(" Another Header");
      wb.cloneSheet(0);

      assertSheetOrder(wb, "Sheet1", "Sheet1 (2)");

      //        FileOutputStream fileOut = new FileOutputStream("/tmp/bug48495.xlsx");
View Full Code Here

    Sheet testSheet  = wb.getSheetAt(0);
    // 1) corrupted xlsx (unreadable data in the first row of a shifted group) already comes about 
    // when shifted by less than -1 negative amount (try -2)
    testSheet.shiftRows(3, 3, -2);
   
    Row newRow = null; Cell newCell = null;
    // 2) attempt to create a new row IN PLACE of a removed row by a negative shift causes corrupted
    // xlsx file with  unreadable data in the negative shifted row.
    // NOTE it's ok to create any other row.
    newRow = testSheet.createRow(3);
    newCell = newRow.createCell(0);
    newCell.setCellValue("new Cell in row "+newRow.getRowNum());
   
    // 3) once a negative shift has been made any attempt to shift another group of rows
    // (note: outside of previously negative shifted rows) by a POSITIVE amount causes POI exception:
    // org.apache.xmlbeans.impl.values.XmlValueDisconnectedException.
    // NOTE: another negative shift on another group of rows is successful, provided no new rows in 
View Full Code Here

TOP

Related Classes of org.apache.poi.ss.usermodel.Row

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.