Examples of XSSFRow


Examples of org.apache.poi.xssf.usermodel.XSSFRow

        
        importer.importFromXML(testXML);
        
        XSSFSheet sheet=wb.getSheetAt(0);
        
         XSSFRow rowHeadings = sheet.getRow(0);
         XSSFRow rowData = sheet.getRow(1);
        
         assertEquals("FirstName", rowHeadings.getCell(0).getStringCellValue());
         assertEquals("Albert", rowData.getCell(0).getStringCellValue());
        
         assertEquals("LastName", rowHeadings.getCell(1).getStringCellValue());
         assertEquals("Einstein", rowData.getCell(1).getStringCellValue());
        
         assertEquals("BirthDate", rowHeadings.getCell(2).getStringCellValue());
         assertEquals("1879-03-14", rowData.getCell(2).getStringCellValue());
        
         // Value for OptionalRating is declared optional (minOccurs=0) in 55864.xlsx
         assertEquals("OptionalRating", rowHeadings.getCell(3).getStringCellValue());
         assertNull("", rowData.getCell(3));
        } finally {
            wb.close();
        }
  }
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFRow

                    String nodeXPath = commonXPath + "[" + (i + 1) + "]" + localXPath;

                    // TODO: convert the data to the cell format
                    String value = (String) xpath.evaluate(nodeXPath, result.item(i), XPathConstants.STRING);
                    logger.log(POILogger.DEBUG, "Extracting with xpath " + nodeXPath + " : value is '" + value + "'");
                    XSSFRow row = table.getXSSFSheet().getRow(rowId);
                    if (row == null) {
                        row = table.getXSSFSheet().createRow(rowId);
                    }

                    XSSFCell cell = row.getCell(columnId);
                    if (cell == null) {
                        cell = row.createCell(columnId);
                    }
                    logger.log(POILogger.DEBUG, "Setting '" + value + "' to cell " + cell.getColumnIndex() + "-" + cell.getRowIndex() + " in sheet "
                                                    + table.getXSSFSheet().getSheetName());
                    cell.setCellValue(value.trim());
                }
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFRow

                    startRow +=1;

                    int endRow = table.getEndCellReference().getRow();

                    for(int i = startRow; i<= endRow; i++) {
                        XSSFRow row = sheet.getRow(i);

                        Node tableRootNode = getNodeByXPath(table.getCommonXpath(),doc.getFirstChild(),doc,true);

                        short startColumnIndex = table.getStartCellReference().getCol();
                        for(int j = startColumnIndex; j<= table.getEndCellReference().getCol();j++) {
                            XSSFCell cell = row.getCell(j);
                            if (cell!=null) {
                                XSSFXmlColumnPr pointer = tableColumns.get(j-startColumnIndex);
                                String localXPath = pointer.getLocalXPath();
                                Node currentNode = getNodeByXPath(localXPath,tableRootNode,doc,false);
                                STXmlDataType.Enum dataType = pointer.getXmlDataType();
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFRow

        }
    }

    private void updateSheetFormulas(XSSFSheet sh, FormulaShifter shifter) {
        for (Row r : sh) {
            XSSFRow row = (XSSFRow) r;
            updateRowFormulas(row, shifter);
        }
    }
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFRow

            XSSFSheet sheet = wb.getSheetAt(sheetNum);
            if (sheet != null)
            {
               for (int rowNum = sheet.getFirstRowNum(); rowNum <= sheet.getLastRowNum(); rowNum++)
               {
                  XSSFRow row = sheet.getRow(rowNum);

                  if (row != null)
                  {
                     int lastcell = row.getLastCellNum();
                     for (int k = 0; k < lastcell; k++)
                     {
                        XSSFCell cell = row.getCell(k);
                        if (cell != null)
                        {
                           switch (cell.getCellType())
                           {
                              case XSSFCell.CELL_TYPE_NUMERIC : {
View Full Code Here

Examples of org.apache.poi.xssf.usermodel.XSSFRow

    sheet.setColumnWidth(5, 50*255);   
    sheet.setColumnWidth(6, 15*255);   
    sheet.setColumnWidth(7, 20*255)
    sheet.setColumnWidth(8, 10*255);   
    //创建第一行
    XSSFRow row=sheet.createRow(0);
    //表头样式
        XSSFFont fonttitle=wb.createFont();
        fonttitle.setItalic(true);
        fonttitle.setFontName("微软雅黑");
        fonttitle.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);//粗体
       
            CellStyle styletitle = wb.createCellStyle();
            styletitle.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
            styletitle.setFillPattern(CellStyle.SOLID_FOREGROUND);
            styletitle.setFont(fonttitle);
            styletitle.setBorderLeft(CellStyle.BORDER_THIN);
            styletitle.setBorderRight(CellStyle.BORDER_THIN);
            styletitle.setBorderTop(CellStyle.BORDER_THIN);
            styletitle.setBorderBottom(CellStyle.BORDER_THIN);
           
      //正文样式
            //
            XSSFFont fontRed=wb.createFont();
            fontRed.setColor(HSSFColor.GREEN.index);
            fontRed.setColor(IndexedColors.RED.getIndex());
            fontRed.setFontName("微软雅黑");
            fontRed.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);//粗体
            fontRed.setFontHeightInPoints((short) 11);
        CellStyle styleRed = wb.createCellStyle();
        styleRed.setFont(fontRed);
        styleRed.setBorderLeft(CellStyle.BORDER_THIN);
        styleRed.setBorderRight(CellStyle.BORDER_THIN);
        styleRed.setBorderTop(CellStyle.BORDER_THIN);
        styleRed.setBorderBottom(CellStyle.BORDER_THIN);
           
            XSSFFont fontGreen=wb.createFont();
            fontGreen.setColor(IndexedColors.GREEN.getIndex());
            fontGreen.setFontName("微软雅黑");
            fontGreen.setBoldweight(XSSFFont.BOLDWEIGHT_BOLD);//粗体
            fontGreen.setFontHeightInPoints((short) 11);
        CellStyle styleGreen = wb.createCellStyle();
        styleGreen.setFont(fontGreen);
        styleGreen.setBorderLeft(CellStyle.BORDER_THIN);
        styleGreen.setBorderRight(CellStyle.BORDER_THIN);
        styleGreen.setBorderTop(CellStyle.BORDER_THIN);
        styleGreen.setBorderBottom(CellStyle.BORDER_THIN);
       
            XSSFFont fontBlack=wb.createFont();
            fontBlack.setColor(IndexedColors.BLACK.getIndex());
            fontBlack.setFontName("Arial");
            fontBlack.setFontHeightInPoints((short) 9);
        CellStyle styleBlack = wb.createCellStyle();
        styleBlack.setFont(fontBlack);
        styleBlack.setBorderLeft(CellStyle.BORDER_THIN);
        styleBlack.setBorderRight(CellStyle.BORDER_THIN);
        styleBlack.setBorderTop(CellStyle.BORDER_THIN);
        styleBlack.setBorderBottom(CellStyle.BORDER_THIN);
    //写入标题
    for (int i = 0; i < title.size(); i++) {
      XSSFCell cell=row.createCell(i, XSSFCell.CELL_TYPE_STRING);
      cell.setCellValue(title.get(i));
      cell.setCellStyle(styletitle);
    }
   
    // 写入内容行
    for (int i = 0; i < datas.size(); i++) {
      String[] rowvalue = datas.get(i);
      XSSFRow nextrow = sheet.createRow(sheet.getLastRowNum() + 1);// 创建一行
      for (int j = 0; j < rowvalue.length; j++) {
        XSSFCell cell = nextrow
            .createCell(j, XSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(new XSSFRichTextString(rowvalue[j]));
        if (rowvalue[j].equals("Fail")) {
          cell.setCellStyle(styleRed);
        } else if (rowvalue[j].equals("Pass")) {
View Full Code Here

Examples of org.zkoss.poi.xssf.usermodel.XSSFRow

     */
    public List<CellRangeAddress[]>  shiftRowsOnly(int startRow, int endRow, int n, boolean copyRowHeight, boolean resetOriginalRowHeight,
        boolean moveComments, boolean clearRest, int copyOrigin) {
      //prepare source format row
      final int srcRownum = n <= 0 ? -1 : copyOrigin == Range.FORMAT_RIGHTBELOW ? startRow : copyOrigin == Range.FORMAT_LEFTABOVE ? startRow - 1 : -1;
      final XSSFRow srcRow = srcRownum >= 0 ? getRow(srcRownum) : null;
      final Map<Integer, Cell> srcCells = srcRow != null ? BookHelper.copyRowCells(srcRow, srcRow.getFirstCellNum(), srcRow.getLastCellNum()) : null;
      final short srcHeight = srcRow != null ? srcRow.getHeight() : -1;
//      final XSSFCellStyle srcStyle = srcRow != null ? srcRow.getRowStyle() : null;
     
        final int maxrow = SpreadsheetVersion.EXCEL2007.getLastRowIndex();
        final int maxcol = SpreadsheetVersion.EXCEL2007.getLastColumnIndex();
        final List<CellRangeAddress[]> shiftedRanges = BookHelper.shiftMergedRegion(this, startRow, 0, endRow, maxcol, n, false);
     
      //shift the rows (actually change the row number only)
        for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
            XSSFRow row = (XSSFRow)it.next();
            int rownum = row.getRowNum();
            if(rownum < startRow) continue;
           
            final int newrownum = rownum + n;
            final boolean inbound = 0 <= newrownum && newrownum <= maxrow;
            if (!inbound) {
              row.removeAllCells();
              it.remove();
              continue;
            }
           
            if (!copyRowHeight) {
                row.setHeight((short)-1);
            }

            if (canRemoveRow(startRow, endRow, n, rownum)) {
                it.remove();
            } else if (rownum >= startRow && rownum <= endRow) {
                new XSSFRowHelper(row).shift(n);
            }
            if (moveComments) {
              final CommentsTable sheetComments = getCommentsTable(false);
              if(sheetComments != null){
                  //TODO shift Note's anchor in the associated /xl/drawing/vmlDrawings#.vml
                  CTCommentList lst = sheetComments.getCTComments().getCommentList();
                  for (CTComment comment : lst.getCommentArray()) {
                      CellReference ref = new CellReference(comment.getRef());
                      if(ref.getRow() == rownum){
                          ref = new CellReference(rownum + n, ref.getCol());
                          comment.setRef(ref.formatAsString());
                      }
                  }
              }
            }
        }
       
        //rebuild the _rows map ASAP or getRow(rownum) will be incorrect
        TreeMap<Integer, XSSFRow> rows = getRows();
        TreeMap<Integer, XSSFRow> map = new TreeMap<Integer, XSSFRow>();
        for(XSSFRow r : rows.values()) {
            map.put(r.getRowNum(), r);
        }
        setRows(map);
       
        //handle inserted rows
        if (srcRow != null) {
          final int row2 = Math.min(startRow + n - 1, SpreadsheetVersion.EXCEL2007.getLastRowIndex());
          for ( int rownum = startRow; rownum <= row2; ++rownum) {
            XSSFRow row = getRow(rownum);
            if (row == null) {
              row = createRow(rownum);
            }
            row.setHeight(srcHeight); //height
//            if (srcStyle != null) {
//              row.setRowStyle((HSSFCellStyle)copyFromStyleExceptBorder(srcStyle));//style
//            }
            if (srcCells != null) {
              for (Entry<Integer, Cell> cellEntry : srcCells.entrySet()) {
                final Cell srcCell = cellEntry.getValue();
                final CellStyle cellStyle = srcCell.getCellStyle();
                final int c = cellEntry.getKey().intValue();
                Cell cell = row.getCell(c);
                if (cell == null) {
                  cell = row.createCell(c);
                }
                cell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), cellStyle));
              }
            }
          }
        }
       
        // Shift Hyperlinks which have been moved
        shiftHyperlinks(startRow, endRow, n, 0, maxcol, 0);
       
        //special case1: endRow < startRow
        //special case2: (endRow - startRow + 1) < ABS(n)
        if (n < 0) {
          if (endRow < startRow) { //special case1
          final int orgStartRow = startRow + n;
              for ( int rowNum = orgStartRow; rowNum >= orgStartRow && rowNum <= endRow && rowNum >= 0 && rowNum <= maxrow; ++rowNum) {
                  final XSSFRow row = getRow( rowNum );
                  if (row != null) {
                    removeRow(row);
                  }
              }
              removeHyperlinks(orgStartRow, endRow, 0, maxcol);
            } else if (clearRest) { //special case 2
              final int orgStartRow = endRow + n + 1;
              if (orgStartRow <= startRow) {
                  for ( int rowNum = orgStartRow; rowNum >= orgStartRow && rowNum <= startRow && rowNum >= 0 && rowNum <= maxrow; ++rowNum) {
                      final XSSFRow row = getRow( rowNum );
                      if (row != null) {
                        removeRow(row);
                      }
                  }
                  removeHyperlinks(orgStartRow, startRow, 0, maxcol);
View Full Code Here

Examples of org.zkoss.poi.xssf.usermodel.XSSFRow

     */
    public List<CellRangeAddress[]> shiftRowsRange(int startRow, int endRow, int n, int lCol, int rCol,
            boolean copyRowHeight, boolean resetOriginalRowHeight, boolean moveComments, boolean clearRest, int copyOrigin) {
      //prepare source format row
      final int srcRownum = n <= 0 ? -1 : copyOrigin == Range.FORMAT_RIGHTBELOW ? startRow : copyOrigin == Range.FORMAT_LEFTABOVE ? startRow - 1 : -1;
      final XSSFRow srcRow = srcRownum >= 0 ? getRow(srcRownum) : null;
      final Map<Integer, Cell> srcCells = srcRow != null ? BookHelper.copyRowCells(srcRow, lCol, rCol) : null;
      final short srcHeight = srcRow != null ? srcRow.getHeight() : -1;
//      final XSSFCellStyle srcStyle = srcRow != null ? srcRow.getRowStyle() : null;
     
        final int maxrow = SpreadsheetVersion.EXCEL2007.getLastRowIndex();
        final int maxcol = SpreadsheetVersion.EXCEL2007.getLastColumnIndex();
        if (endRow < 0) {
          endRow = maxrow;
        }
        final List<CellRangeAddress[]> shiftedRanges = BookHelper.shiftMergedRegion(this, startRow, lCol, endRow, rCol, n, false);
        final boolean wholeRow = lCol == 0 && rCol == maxcol;
     
        final List<int[]> removePairs = new ArrayList<int[]>(); //row spans to be removed
        final TreeMap<Integer, TreeMap<Integer, XSSFCell>> rowCells = new TreeMap<Integer, TreeMap<Integer, XSSFCell>>();
        int expectRownum = startRow; //handle sparse rows which might override destination row
        for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) { //TODO use submap between startRow and endRow
            XSSFRow row = (XSSFRow)it.next();
            int rownum = row.getRowNum();
            if (rownum < startRow) continue;
            if (rownum > endRow) break; //no more
           
            final int newRownum = rownum + n;
            if (rownum > expectRownum) { //sparse row between expectRownum(inclusive) and current row(exclusive), to be removed
              addRemovePair(removePairs, expectRownum + n, newRownum);
            }
            expectRownum = rownum + 1;
           
            final boolean inbound = 0 <= newRownum && newRownum <= maxrow;
            if (!inbound) {
              row.removeAllCells();
              it.remove();
              continue;
            }
           
            if (wholeRow) {
              if (!copyRowHeight) {
                  row.setHeight((short)-1);
              }
              if (canRemoveRow(startRow, endRow, n, rownum)) {
                  it.remove();
              }
              else if (rownum >= startRow && rownum <= endRow) {
                  new XSSFRowHelper(row).shift(n);
              }
            } else {
              SortedMap<Integer, XSSFCell> oldCells = row.getCells().subMap(Integer.valueOf(lCol), Integer.valueOf(rCol+1));
              if (!oldCells.isEmpty()) {
                TreeMap<Integer, XSSFCell> cells = new TreeMap<Integer, XSSFCell>(oldCells);
                rowCells.put(newRownum, cells);
                for (Cell cell : cells.values()) {
                  row.removeCell(cell);
                }
              }
            }
           
            if (moveComments) {
              final CommentsTable sheetComments = getCommentsTable(false);
              if(sheetComments != null){
                  //TODO shift Note's anchor in the associated /xl/drawing/vmlDrawings#.vml
                  CTCommentList lst = sheetComments.getCTComments().getCommentList();
                  for (CTComment comment : lst.getCommentArray()) {
                      CellReference ref = new CellReference(comment.getRef());
                      final int colnum = ref.getCol();
                      if(ref.getRow() == rownum && lCol <= colnum && colnum <= rCol){
                          ref = new CellReference(rownum + n, colnum);
                          comment.setRef(ref.formatAsString());
                      }
                  }
              }
            }
        }

        //rebuild rows ASAP or the getRow(rownum) will be incorrect
        if (wholeRow) {
          TreeMap<Integer, XSSFRow> map = new TreeMap<Integer, XSSFRow>();
          TreeMap<Integer, XSSFRow> rows = getRows();
          for(XSSFRow r : rows.values()) {
              map.put(r.getRowNum(), r);
          }
          setRows(map);
        }
       
        //sparse row between expectRownum(inclusive) to endRow+1(exclusive), to be removed
      addRemovePair(removePairs, expectRownum + n, endRow + 1 + n);
     
        //really remove rows
        if (wholeRow) {
          for(int[] pair : removePairs) {
            final int start = Math.max(0, pair[0]);
            final int end = Math.min(SpreadsheetVersion.EXCEL2007.getLastRowIndex() + 1, pair[1]);
            for(int j=start; j < end; ++j) {
              Row row = getRow(j);
              if (row != null) {
                removeRow(row);
              }
            }
          }
        } else { //clear cells between lCol and rCol
          for(int[] pair : removePairs) {
            final int start = Math.max(0, pair[0]);
            final int end = pair[1];
            for(int j=start; j < end; ++j) {
              Row row = getRow(j);
              if (row != null) {
                removeCells(row, lCol, rCol);
              }
            }
          }
        }
       
        //really update the row's cells
        for (Entry<Integer, TreeMap<Integer, XSSFCell>> entry : rowCells.entrySet()) {
          final int rownum = entry.getKey().intValue();
          final TreeMap<Integer, XSSFCell> cells = entry.getValue();
          XSSFRow row = getRow(rownum);
          if (row == null) {
            row = createRow(rownum);
          } else {
            removeCells(row, lCol, rCol);
          }
          for(Entry<Integer, XSSFCell> cellentry : cells.entrySet()) {
            final int colnum = cellentry.getKey().intValue();
            final XSSFCell srcCell = cellentry.getValue();
            BookHelper.assignCell(srcCell, row.createCell(colnum));
          }
        }
       
        //handle inserted rows
        if (srcRow != null) {
          final int row2 = Math.min(startRow + n - 1, SpreadsheetVersion.EXCEL2007.getLastRowIndex());
          for ( int rownum = startRow; rownum <= row2; ++rownum) {
            XSSFRow row = getRow(rownum);
            if (row == null) {
              row = createRow(rownum);
            }
            row.setHeight(srcHeight); //height
//            if (srcStyle != null) {
//              row.setRowStyle((HSSFCellStyle)copyFromStyleExceptBorder(srcStyle));//style
//            }
            if (srcCells != null) {
              for (Entry<Integer, Cell> cellEntry : srcCells.entrySet()) {
                final Cell srcCell = cellEntry.getValue();
                final CellStyle cellStyle = srcCell.getCellStyle();
                final int c = cellEntry.getKey().intValue();
                Cell cell = row.getCell(c);
                if (cell == null) {
                  cell = row.createCell(c);
                }
                cell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), cellStyle));
              }
            }
          }
        }
       
        // Shift Hyperlinks which have been moved
        shiftHyperlinks(startRow, endRow, n, 0, maxcol, 0);
       
        //special case1: endRow < startRow
        //special case2: (endRow - startRow + 1) < ABS(n)
        if (n < 0) {
          if (endRow < startRow) { //special case1
          final int orgStartRow = startRow + n;
              for ( int rowNum = orgStartRow; rowNum >= orgStartRow && rowNum <= endRow && rowNum >= 0 && rowNum <= maxrow; ++rowNum) {
                  final XSSFRow row = getRow( rowNum );
                  if (row != null) {
                    removeRow(row);
                  }
              }
              removeHyperlinks(orgStartRow, endRow, 0, maxcol);
            } else if (clearRest) { //special case 2
              final int orgStartRow = endRow + n + 1;
              if (orgStartRow <= startRow) {
                  for ( int rowNum = orgStartRow; rowNum >= orgStartRow && rowNum <= startRow && rowNum >= 0 && rowNum <= maxrow; ++rowNum) {
                      final XSSFRow row = getRow( rowNum );
                      if (row != null) {
                        removeRow(row);
                      }
                  }
                  removeHyperlinks(orgStartRow, startRow, 0, maxcol);
View Full Code Here

Examples of org.zkoss.poi.xssf.usermodel.XSSFRow

      final int colWidth = srcCol >= 0 ? getColumnWidth(srcCol) : -1;
      final Map<Integer, Cell> cells = srcCol >= 0 ? new HashMap<Integer, Cell>() : null;
     
      int maxColNum = -1;
        for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
            XSSFRow row = (XSSFRow)it.next();
            int rowNum = row.getRowNum();
           
            if (endCol < 0) {
              final int colNum = row.getLastCellNum() - 1;
              if (colNum > maxColNum)
                maxColNum = colNum;
            }
           
            if (cells != null) {
               final Cell cell = row.getCell(srcCol);
               if (cell != null) {
                 cells.put(Integer.valueOf(rowNum), cell);
               }
            }
           
            shiftCells(row, startCol, endCol, n, clearRest);
        }
       
        if (endCol < 0) {
          endCol = maxColNum;
        }
        if (n > 0) {
          if (startCol > endCol) { //nothing to do
            return Collections.emptyList();
          }
        } else {
          if ((startCol + n) > endCol) { //nothing to do
            return Collections.emptyList();
          }
        }
       
        final int maxrow = SpreadsheetVersion.EXCEL2007.getLastRowIndex();
        final int maxcol = SpreadsheetVersion.EXCEL2007.getLastColumnIndex();
        final List<CellRangeAddress[]> shiftedRanges = BookHelper.shiftMergedRegion(this, 0, startCol, maxrow, endCol, n, true);
       
        //TODO handle the page breaks
        //?

        // Move comments from the source column to the
        //  destination column. Note that comments can
        //  exist for cells which are null
        if (moveComments) {
            final CommentsTable sheetComments = getCommentsTable(false);
            if(sheetComments != null){
                //TODO shift Note's anchor in the associated /xl/drawing/vmlDrawings#.vml
                CTCommentList lst = sheetComments.getCTComments().getCommentList();
                for (final Iterator<CTComment> it = lst.getCommentList().iterator(); it.hasNext();) {
                  CTComment comment = it.next();
                    CellReference ref = new CellReference(comment.getRef());
                    final int colnum = ref.getCol();
                    if(startCol <= colnum && colnum <= endCol){
                      int newColNum = colnum + n;
                      if (newColNum < 0 || newColNum > maxcol) { //out of bound, shall remove it
                        it.remove();
                      } else {
                          ref = new CellReference(ref.getRow(), newColNum);
                          comment.setRef(ref.formatAsString());
                      }
                    }
                }
            }
        }
       
        // Fix up column width if required
        int s, inc;
        if (n < 0) {
            s = startCol;
            inc = 1;
        } else {
            s = endCol;
            inc = -1;
        }

        if (copyColWidth || resetOriginalColWidth) {
          final int defaultColumnWidth = getDefaultColumnWidth();
          for ( int colNum = s; colNum >= startCol && colNum <= endCol && colNum >= 0 && colNum <= maxcol; colNum += inc ) {
            final int newColNum = colNum + n;
            if (copyColWidth) {
                setColumnWidth(newColNum, getColumnWidth(colNum));
            }
            if (resetOriginalColWidth) {
                setColumnWidth(colNum, defaultColumnWidth);
            }
          }
        }

        //handle inserted columns
        if (srcCol >= 0) {
          final int col2 = Math.min(startCol + n - 1, maxcol);
          for (int col = startCol; col <= col2 ; ++col) {
            //copy the column width
            setColumnWidth(col, colWidth);
            if (colStyle != null) {
              setDefaultColumnStyle(col, BookHelper.copyFromStyleExceptBorder(getBook(), colStyle));
            }
          }
          if (cells != null) {
            for (Entry<Integer, Cell> cellEntry : cells.entrySet()) {
                final XSSFRow row = getRow(cellEntry.getKey().intValue());
                final Cell srcCell = cellEntry.getValue();
                final CellStyle srcStyle = srcCell.getCellStyle();
              for (int col = startCol; col <= col2; ++col) {
                Cell dstCell = row.getCell(col);
                if (dstCell == null) {
                  dstCell = row.createCell(col);
                }
                dstCell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), srcStyle));
              }
            }
          }
View Full Code Here

Examples of org.zkoss.poi.xssf.usermodel.XSSFRow

      int startRow = Math.max(tRow, getFirstRowNum());
      int endRow = Math.min(bRow, getLastRowNum());
      int maxColNum = -1;
      if (startRow <= endRow) {
          for (Iterator<XSSFRow> it = getRows().subMap(startRow, endRow+1).values().iterator(); it.hasNext() ; ) {
              XSSFRow row = it.next();
              int rowNum = row.getRowNum();
             
              if (endCol < 0) {
                final int colNum = row.getLastCellNum() - 1;
                if (colNum > maxColNum)
                  maxColNum = colNum;
              }
             
              if (cells != null) {
                 final Cell cell = row.getCell(srcCol);
                 if (cell != null) {
                   cells.put(Integer.valueOf(rowNum), cell);
                 }
              }
             
              shiftCells(row, startCol, endCol, n, clearRest);
          }
      }
       
        if (endCol < 0) {
          endCol = maxColNum;
        }
        if (n > 0) {
          if (startCol > endCol) { //nothing to do
            return Collections.emptyList();
          }
        } else {
          if ((startCol + n) > endCol) { //nothing to do
            return Collections.emptyList();
          }
        }
       
        final int maxrow = SpreadsheetVersion.EXCEL2007.getLastRowIndex();
        final int maxcol = SpreadsheetVersion.EXCEL2007.getLastColumnIndex();
        final List<CellRangeAddress[]> shiftedRanges = BookHelper.shiftMergedRegion(this, tRow, startCol, bRow, endCol, n, true);
        final boolean wholeColumn = tRow == 0 && bRow == maxrow;
        if (wholeColumn) {
          //TODO handle the page breaks
          //?
        }

        // Move comments from the source column to the
        //  destination column. Note that comments can
        //  exist for cells which are null
        if (moveComments) {
            final CommentsTable sheetComments = getCommentsTable(false);
            if(sheetComments != null){
                //TODO shift Note's anchor in the associated /xl/drawing/vmlDrawings#.vml
                CTCommentList lst = sheetComments.getCTComments().getCommentList();
                for (final Iterator<CTComment> it = lst.getCommentList().iterator(); it.hasNext();) {
                  CTComment comment = it.next();
                    CellReference ref = new CellReference(comment.getRef());
                    final int colnum = ref.getCol();
                    final int rownum = ref.getRow();
                    if(startCol <= colnum && colnum <= endCol && tRow <= rownum && rownum <= bRow){
                      int newColNum = colnum + n;
                      if (newColNum < 0 || newColNum > maxcol) { //out of bound, shall remove it
                        it.remove();
                      } else {
                          ref = new CellReference(ref.getRow(), newColNum);
                          comment.setRef(ref.formatAsString());
                      }
                    }
                }
            }
        }
       
        // Fix up column width if required
        int s, inc;
        if (n < 0) {
            s = startCol;
            inc = 1;
        } else {
            s = endCol;
            inc = -1;
        }

        if (wholeColumn && (copyColWidth || resetOriginalColWidth)) {
          final int defaultColumnWidth = getDefaultColumnWidth();
          for ( int colNum = s; colNum >= startCol && colNum <= endCol && colNum >= 0 && colNum <= maxcol; colNum += inc ) {
            final int newColNum = colNum + n;
            if (copyColWidth) {
                setColumnWidth(newColNum, getColumnWidth(colNum));
            }
            if (resetOriginalColWidth) {
                setColumnWidth(colNum, defaultColumnWidth);
            }
          }
        }

        //handle inserted columns
        if (srcCol >= 0) {
          final int col2 = Math.min(startCol + n - 1, maxcol);
          if (wholeColumn) {
            for (int col = startCol; col <= col2 ; ++col) {
              //copy the column width
              setColumnWidth(col, colWidth);
              if (colStyle != null) {
                setDefaultColumnStyle(col, BookHelper.copyFromStyleExceptBorder(getBook(), colStyle));
              }
            }
          }
          if (cells != null) {
            for (Entry<Integer, Cell> cellEntry : cells.entrySet()) {
                final XSSFRow row = getRow(cellEntry.getKey().intValue());
                final Cell srcCell = cellEntry.getValue();
                final CellStyle srcStyle = srcCell.getCellStyle();
              for (int col = startCol; col <= col2; ++col) {
                Cell dstCell = row.getCell(col);
                if (dstCell == null) {
                  dstCell = row.createCell(col);
                }
                dstCell.setCellStyle(BookHelper.copyFromStyleExceptBorder(getBook(), srcStyle));
              }
            }
          }
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.