增加一张图片。

@param sheet               表单
@param cpImageName         类路径中的图片文件名称
@param anchorCellReference 图片锚定单元格索引
179900
@SneakyThrows
    public static void addImage(Sheet sheet, String cpImageName, String anchorCellReference) {
        // add a picture shape
        val anchor = sheet.getWorkbook().getCreationHelper().createClientAnchor();
        anchor.setAnchorType(ClientAnchor.AnchorType.DONT_MOVE_AND_RESIZE);
        // subsequent call of Picture#resize() will operate relative to it
        val cr = new CellReference(anchorCellReference);
        anchor.setCol1(cr.getCol());
        anchor.setRow1(cr.getRow());

        // Create the drawing patriarch.  This is the top level container for all shapes.
        @Cleanup val p = Classpath.loadRes(cpImageName);

        val picIndex = sheet.getWorkbook().addPicture(toByteArray(p), getPictureType(cpImageName));
        val pic = sheet.createDrawingPatriarch().createPicture(anchor, picIndex);
        // auto-size picture relative to its top-left corner
        pic.resize();
    }
206351
public static Row insertRow(final Sheet sheet, final int rowIndex) {

        ArgUtils.notNull(sheet, "cell");
        ArgUtils.notMin(rowIndex, 0, "rowIndex");

        // 最終行を取得する
        int lastRow = sheet.getLastRowNum();
        if(lastRow < rowIndex) {
            // データが定義されている範囲害の場合は、行を新たに作成して返す。
            return sheet.createRow(rowIndex);
        }

        sheet.shiftRows(rowIndex, lastRow+1, 1);
        return sheet.createRow(rowIndex);
    }
300984
public void addCell(Cell aCell, Point aLocation) throws BadElementException {
        if (aCell == null) throw new NullPointerException("addCell - cell has null-value");
        if (aLocation == null) throw new NullPointerException("addCell - point has null-value");
        if (aCell.isTable()) insertTable((Table)aCell.getElements().next(), aLocation);
        
        if (aLocation.x < 0) throw new BadElementException("row coordinate of location must be >= 0");
        if ((aLocation.y <= 0) && (aLocation.y > columns)) throw new BadElementException("column coordinate of location must be >= 0 and < nr of columns");
        if (!isValidLocation(aCell, aLocation)) throw new BadElementException("Adding a cell at the location (" + aLocation.x + "," + aLocation.y + ") with a colspan of " + aCell.getColspan() + " and a rowspan of " + aCell.getRowspan() + " is illegal (beyond boundaries/overlapping).");
        
        if (aCell.getBorder() == UNDEFINED) aCell.setBorder(defaultCell.getBorder());
        aCell.fill();
        placeCell(rows, aCell, aLocation);
        setCurrentLocationToNextValidPosition(aLocation);
    }
878246
public void setCellpadding(java.lang.String cellpadding) {
        getStateHelper().put(PropertyKeys.cellpadding, cellpadding);
        handleAttribute("cellpadding", cellpadding);
    }
511111
@Override
    public void selectRangeExpl(int anchorParagraph, int anchorColumn, int caretParagraph, int caretColumn) {
        selectRangeExpl(textPosition(anchorParagraph, anchorColumn), textPosition(caretParagraph, caretColumn));
    }
1331858
@SuppressWarnings("unchecked")
	public T setSheet(String sheetName) {
		this.sheet = this.workbook.getSheet(sheetName);
		if (null == this.sheet) {
			this.sheet = this.workbook.createSheet(sheetName);
		}
		return (T) this;
	}
1071652
private void placeCell(ArrayList<Row> someRows, Cell aCell, Point aPosition) {
        int i;
        Row row = null;
        int rowCount = aPosition.x + aCell.getRowspan() - someRows.size();
        assumeTableDefaults(aCell);
        if ( (aPosition.x + aCell.getRowspan()) > someRows.size() ) {
            for (i = 0; i < rowCount; i++) {
                row = new Row(columns);
                someRows.add(row);
            }
        }
        
        // reserve cell in rows below
        for (i = aPosition.x + 1; i < (aPosition.x  + aCell.getRowspan()); i++) {
            if ( !someRows.get(i).reserve(aPosition.y, aCell.getColspan())) {
                
                // should be impossible to come here :-)
                throw new RuntimeException("addCell - error in reserve");
            }
        }
        row = someRows.get(aPosition.x);
        row.addElement(aCell, aPosition.y);
        
    }
956387
public static void removeOtherSheets(Sheet sheet) {
        val wb = sheet.getWorkbook();

        List<String> deletedNames = Lists.newArrayList();
        for (int i = 0; i < wb.getNumberOfSheets(); ++i) {
            val sheetName = wb.getSheetName(i);
            if (!sheetName.equals(sheet.getSheetName())) {
                deletedNames.add(sheetName);
            }
        }

        deletedNames.forEach(x -> wb.removeSheetAt(wb.getSheetIndex(x)));
    }
129341
def use_one_cell_anchor
      return if @anchor.is_a?(OneCellAnchor)
      new_anchor = OneCellAnchor.new(@anchor.drawing, :start_at => [@anchor.from.col, @anchor.from.row])
      swap_anchor(new_anchor)
    end
611441
def child_cell(index)
      assert_exists

      if (index - Celerity.index_offset) >= @cells.length
        raise UnknownCellException, "Unable to locate a cell at index #{index}"
      end

      TableCell.new(self, :object, @cells[index - Celerity.index_offset])
    end
271641
public void replaceRowTab(String tabLabel, Component object, String toolTipText) {
        int index = indexOfComponent(rowsTab);
        remove(index);
        ImageIcon rowsIcon = createImageIcon("/kg/apc/jmeter/img/checks.png");
        insertTab(tabLabel, rowsIcon, object, toolTipText, index);
    }
60531
public void addToCell(int index, int element) {
        if (cells.size() < index + 1) {
            addSingletonCell(element);
        } else {
            cells.get(index).add(element);
        }
    }
248617
private void renderCellToHeaderFooter(StringBuilder result, String bandName, BandElement bandElement, Object value, int gridRow, int row,
                              int column, int cols, int rowSpan, int colSpan, boolean isImage) {
    	    	
    	if (newRow) {
    		result.append("\r\n ");
    	} else {
    		result.append(" ");
    	}
    	boolean specialCell = false;
    	if (bandElement instanceof VariableBandElement)  {
        	VariableBandElement vbe = (VariableBandElement)bandElement;
        	Variable var = VariableFactory.getVariable(vbe.getVariable());        	
        	if (var instanceof PageNoVariable) {           		
        		specialCell = true;
        		result.append("&P");
        	} 
    	} else if (bandElement instanceof ExpressionBandElement)  {
         	// special case pageNo inside an expression
         	// bandName is not important here (it is used for groupRow computation)
    		PrefixSuffix pf = interpretPageNo(bandElement);
			if (pf != null) {
				result.append(pf.getPrefix()).append(" &P ").append(pf.getSuffix());     
				specialCell = true;
			}	
    	}
		if (!specialCell) {
			result.append(value);
		}				
    }
1093970
public static Cell searchCell(Sheet sheet, String searchKey) {
        if (StringUtils.isEmpty(searchKey)) return null;

        for (int i = sheet.getFirstRowNum(), ii = sheet.getLastRowNum(); i < ii; ++i) {
            Cell cell = searchRow(sheet.getRow(i), searchKey);
            if (cell != null) return cell;
        }

        return null;
    }
510460
protected void registerCellAttributes() {
        addCellAttributeProcessor(new CellAlignLmlAttribute(), "align");
        addCellAttributeProcessor(new CellColspanLmlAttribute(), "colspan");
        addCellAttributeProcessor(new CellExpandLmlAttribute(), "expand");
        addCellAttributeProcessor(new CellExpandXLmlAttribute(), "expandX");
        addCellAttributeProcessor(new CellExpandYLmlAttribute(), "expandY");
        addCellAttributeProcessor(new CellFillLmlAttribute(), "fill");
        addCellAttributeProcessor(new CellFillXLmlAttribute(), "fillX");
        addCellAttributeProcessor(new CellFillYLmlAttribute(), "fillY");
        addCellAttributeProcessor(new CellGrowLmlAttribute(), "grow");
        addCellAttributeProcessor(new CellGrowXLmlAttribute(), "growX");
        addCellAttributeProcessor(new CellGrowYLmlAttribute(), "growY");
        addCellAttributeProcessor(new CellHeightLmlAttribute(), "height");
        addCellAttributeProcessor(new CellMaxHeightLmlAttribute(), "maxHeight");
        addCellAttributeProcessor(new CellMaxSizeLmlAttribute(), "maxSize");
        addCellAttributeProcessor(new CellMaxWidthLmlAttribute(), "maxWidth");
        addCellAttributeProcessor(new CellMinHeightLmlAttribute(), "minHeight");
        addCellAttributeProcessor(new CellMinSizeLmlAttribute(), "minSize");
        addCellAttributeProcessor(new CellMinWidthLmlAttribute(), "minWidth");
        addCellAttributeProcessor(new CellPadBottomLmlAttribute(), "padBottom");
        addCellAttributeProcessor(new CellPadLeftLmlAttribute(), "padLeft");
        addCellAttributeProcessor(new CellPadLmlAttribute(), "pad");
        addCellAttributeProcessor(new CellPadRightLmlAttribute(), "padRight");
        addCellAttributeProcessor(new CellPadTopLmlAttribute(), "padTop");
        addCellAttributeProcessor(new CellPrefHeightLmlAttribute(), "prefHeight");
        addCellAttributeProcessor(new CellPrefSizeLmlAttribute(), "prefSize");
        addCellAttributeProcessor(new CellPrefWidthLmlAttribute(), "prefWidth");
        addCellAttributeProcessor(new CellSizeLmlAttribute(), "size");
        addCellAttributeProcessor(new CellSpaceBottomLmlAttribute(), "spaceBottom");
        addCellAttributeProcessor(new CellSpaceLeftLmlAttribute(), "spaceLeft");
        addCellAttributeProcessor(new CellSpaceLmlAttribute(), "space");
        addCellAttributeProcessor(new CellSpaceRightLmlAttribute(), "spaceRight");
        addCellAttributeProcessor(new CellSpaceTopLmlAttribute(), "spaceTop");
        addCellAttributeProcessor(new CellUniformLmlAttribute(), "uniform");
        addCellAttributeProcessor(new CellUniformXLmlAttribute(), "uniformX");
        addCellAttributeProcessor(new CellUniformYLmlAttribute(), "uniformY");
        addCellAttributeProcessor(new CellWidthLmlAttribute(), "width");
        addAttributeProcessor(new RowLmlAttribute(), "row"); // Row attribute is not available for default cell.
    }
1094946
private void organizeCells(ArrayList<TextPiece> linesOfAPage,
	    TableCandidate tc) {
	float captionY = linesOfAPage.get(tc.getCaptionStartLine()).getY();
	float captionEndY = linesOfAPage.get(tc.getCaptionEndLine()).getEndY();
	ArrayList<TextPiece> rawCells = new ArrayList<TextPiece>();
	/*
	 * Copy & sort
	 */
	for (int i = tc.getBodyStartLine(); i <= tc.getBodyEndLine(); i++) {
	    rawCells.add(linesOfAPage.get(i));
	}

	Collections.sort(rawCells);
	assert rawCells.size() >= 4; // due to previous check
	TableRow currentRow = null; // creates first row

	for (TextPiece cell : rawCells) {
	    /*
	     * Skips lines beyond caption //TODO: remove the far Y
	     */
	    if (tc.isTopCaption() && (cell.getY() < captionY))
		continue;
	    if (!tc.isTopCaption() && (cell.getEndY() > captionEndY))
		continue;

	    /*
	     * Lines too close to each other are treated as a single line
	     */
	    if (currentRow != null
		    && cell.getY() - currentRow.getY() < m_docInfo
			    .getAverageLineGap() / 2.0)
		currentRow.addCell(cell);
	    else {
		/*
		 * Creates a new row
		 */
		currentRow = new TableRow();
		currentRow.setY(cell.getY());
		if (cell.isSuperScriptBeginning())
		    currentRow.setSuperScriptRow(true);
		currentRow.addCell(cell);
		tc.addRow(currentRow);
	    }
	}
	if (tc.getRows().size() < 2)
	    tc.setValid(false);
    }
718427
@Override
     public Component getTableCellRendererComponent(JTable table, Object value,
             boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) {
         // 'value' is value contained in the cell located at
         // (rowIndex, vColIndex)

         if (isSelected) {
             // cell (and perhaps other cells) are selected
         }

         if (hasFocus) {
             // this cell is the anchor and the table has the focus
         }

         JComponent result = label;
         // Configure the component with the specified value
         if (!value.toString().equals("")) {
             result = button;
             ((JButton) button).setText(value.toString());
         }

         // Set tool tip if desired
         //setToolTipText((String)value);

         // Since the renderer is a component, return itself
         return result;
     }