当前位置: 首页>>代码示例>>Java>>正文


Java ClientAnchor.setCol2方法代码示例

本文整理汇总了Java中org.apache.poi.ss.usermodel.ClientAnchor.setCol2方法的典型用法代码示例。如果您正苦于以下问题:Java ClientAnchor.setCol2方法的具体用法?Java ClientAnchor.setCol2怎么用?Java ClientAnchor.setCol2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.poi.ss.usermodel.ClientAnchor的用法示例。


在下文中一共展示了ClientAnchor.setCol2方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setComment

import org.apache.poi.ss.usermodel.ClientAnchor; //导入方法依赖的package包/类
/**
 * See the comment for the given cell
 * 
 * @param cell
 *            the cell
 * @param message
 *            the comment message
 */
public static void setComment(HSSFCell cell, String message) {
	Drawing drawing = cell.getSheet().createDrawingPatriarch();
	CreationHelper factory = cell.getSheet().getWorkbook().getCreationHelper();

	// When the comment box is visible, have it show in a 1x3 space
	ClientAnchor anchor = factory.createClientAnchor();
	anchor.setCol1(cell.getColumnIndex());
	anchor.setCol2(cell.getColumnIndex() + 1);
	anchor.setRow1(cell.getRowIndex());
	anchor.setRow2(cell.getRowIndex() + 1);
	anchor.setDx1(100);
	anchor.setDx2(1000);
	anchor.setDy1(100);
	anchor.setDy2(1000);

	// Create the comment and set the text+author
	Comment comment = drawing.createCellComment(anchor);
	RichTextString str = factory.createRichTextString(message);
	comment.setString(str);
	comment.setAuthor("TURNUS");
	// Assign the comment to the cell
	cell.setCellComment(comment);
}
 
开发者ID:turnus,项目名称:turnus,代码行数:32,代码来源:PoiUtils.java

示例2: setImage

import org.apache.poi.ss.usermodel.ClientAnchor; //导入方法依赖的package包/类
/**
 * セルに対し画像を設定します。
 * @param c セル。
 * @param value 値。
 * @param p セル位置情報。
 */
private void setImage(final Cell c, final Object value, final CellPosition p) {
	ImageData img = (ImageData) value;
	int cidx = c.getColumnIndex();
	int ridx = c.getRowIndex();
	ClientAnchor anchor = new XSSFClientAnchor();
	anchor.setCol1(cidx);
	anchor.setCol2(cidx + p.getColumns());
	anchor.setRow1(ridx);
	anchor.setRow2(ridx + p.getRows());
	anchor.setDx1(XSSFShape.EMU_PER_PIXEL * p.getDx1());
	anchor.setDy1(XSSFShape.EMU_PER_PIXEL * p.getDy1());
	anchor.setDx2(XSSFShape.EMU_PER_PIXEL * p.getDx2());
	anchor.setDy2(XSSFShape.EMU_PER_PIXEL * p.getDy2());
	anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE);
	int imgtype = XSSFWorkbook.PICTURE_TYPE_PNG;
	if (ImageData.CONTENT_TYPE_JPEG.equals(img.getContentType())) {
		imgtype = XSSFWorkbook.PICTURE_TYPE_JPEG;
	} else if (ImageData.CONTENT_TYPE_GIF.equals(img.getContentType())) {
		imgtype = XSSFWorkbook.PICTURE_TYPE_GIF;
	}
	int pidx = this.workbook.addPicture(img.getContents(), imgtype);
	Picture pic = this.drawing.createPicture(anchor, pidx);
	this.resizeImage(c, pic, p);
}
 
开发者ID:takayanagi2087,项目名称:dataforms,代码行数:31,代码来源:ExcelReport.java

示例3: extractPicturePortion

import org.apache.poi.ss.usermodel.ClientAnchor; //导入方法依赖的package包/类
/**
 * 抽象出图片生成业务代码
 * 
 * @throws IOException
 */
private void extractPicturePortion(String svgString, XSSFWorkbook wb,
		XSSFSheet sheet, int startCol, int endCol, int startRow, int endRow)
		throws IOException {
	// 图片
	if (org.apache.commons.lang3.StringUtils.isNotBlank(svgString)) {
		byte[] safeDataBytes = new BASE64Decoder().decodeBuffer(svgString);
		int pictureIdx = wb.addPicture(safeDataBytes,
				Workbook.PICTURE_TYPE_JPEG);
		CreationHelper helper = wb.getCreationHelper();
		// Create the drawing patriarch. This is the top level container for
		// all shapes.
		Drawing drawing = sheet.createDrawingPatriarch();
		// add a picture shape
		ClientAnchor anchor = helper.createClientAnchor();
		// set top-left corner of the picture,
		// subsequent call of Picture#resize() will operate relative to it
		anchor.setCol1(startCol);
		anchor.setCol2(endCol);
		anchor.setRow1(startRow);
		anchor.setRow2(endRow);
		anchor.setDx1(0);
		anchor.setDy1(0);
		anchor.setDx2(0);
		anchor.setDy2(0);
		anchor.setAnchorType(ClientAnchor.MOVE_DONT_RESIZE);
		Picture pict = drawing.createPicture(anchor, pictureIdx);
		pict.resize(1);
	}
}
 
开发者ID:gp15237125756,项目名称:PoiExcelExport,代码行数:35,代码来源:ExcelExportService.java

示例4: inlineToXls

import org.apache.poi.ss.usermodel.ClientAnchor; //导入方法依赖的package包/类
@Override
public void inlineToXls(HSSFPatriarch patriarch, HSSFCell resultCell, Object paramValue, Matcher paramsMatcher) {
    try {
        Image image = new Image(paramValue, paramsMatcher);
        if (image.isValid()) {
            HSSFSheet sheet = resultCell.getSheet();
            HSSFWorkbook workbook = sheet.getWorkbook();

            int pictureIdx = workbook.addPicture(image.imageContent, Workbook.PICTURE_TYPE_JPEG);

            CreationHelper helper = workbook.getCreationHelper();
            ClientAnchor anchor = helper.createClientAnchor();
            anchor.setCol1(resultCell.getColumnIndex());
            anchor.setRow1(resultCell.getRowIndex());
            anchor.setCol2(resultCell.getColumnIndex());
            anchor.setRow2(resultCell.getRowIndex());
            if (patriarch == null) {
                throw new IllegalArgumentException(String.format("No HSSFPatriarch object provided. Charts on this sheet could cause this effect. Please check sheet %s", resultCell.getSheet().getSheetName()));
            }
            HSSFPicture picture = patriarch.createPicture(anchor, pictureIdx);
            Dimension size = ImageUtils.getDimensionFromAnchor(picture);
            double actualHeight = size.getHeight() / EMU_PER_PIXEL;
            double actualWidth = size.getWidth() / EMU_PER_PIXEL;
            picture.resize((double) image.width / actualWidth, (double) image.height / actualHeight);
        }
    } catch (IllegalArgumentException e) {
        throw new ReportFormattingException("An error occurred while inserting bitmap to xls file", e);
    }
}
 
开发者ID:cuba-platform,项目名称:yarg,代码行数:30,代码来源:AbstractInliner.java

示例5: writeHeader

import org.apache.poi.ss.usermodel.ClientAnchor; //导入方法依赖的package包/类
protected void writeHeader(Sheet sheet, Drawing drawing, Row nameRow, Row labelRow, int i, ExcelColumn column, CellStyle boldStyle)
{
  CreationHelper helper = sheet.getWorkbook().getCreationHelper();

  // Notify the listeners
  for (ExcelExportListener listener : listeners)
  {
    listener.preHeader(column);
  }

  nameRow.createCell(i).setCellValue(helper.createRichTextString(column.getAttributeName()));

  Cell cell = labelRow.createCell(i);
  cell.setCellValue(helper.createRichTextString(column.getDisplayLabel()));

  if (column.isRequired() && boldStyle != null)
  {
    cell.setCellStyle(boldStyle);
  }

  if (column.getDescription() != null && column.getDescription().length() > 0)
  {
    ClientAnchor anchor = helper.createClientAnchor();
    anchor.setDx1(0);
    anchor.setDy1(0);
    anchor.setDx2(0);
    anchor.setDy2(0);
    anchor.setCol1(0);
    anchor.setRow1(0);
    anchor.setCol2(0);
    anchor.setRow2(4);

    Comment comment = drawing.createCellComment(anchor);
    comment.setString(helper.createRichTextString(column.getDescription()));

    cell.setCellComment(comment);
  }

  sheet.autoSizeColumn((short) i);
}
 
开发者ID:terraframe,项目名称:Runway-SDK,代码行数:41,代码来源:ExcelExportSheet.java

示例6: write

import org.apache.poi.ss.usermodel.ClientAnchor; //导入方法依赖的package包/类
/**
* Add a cell to the current Workbook
*
* @param newDAO cell to add. If it is already existing an exception will be thrown. Note that the sheet name is sanitized using  org.apache.poi.ss.util.WorkbookUtil.createSafeSheetName. The Cell address needs to be in A1 format. Either formula or formattedValue must be not null.
*
*/
@Override
public void write(Object newDAO) throws OfficeWriterException {
	
	SpreadSheetCellDAO sscd = checkSpreadSheetCellDAO(newDAO);
	String safeSheetName=WorkbookUtil.createSafeSheetName(sscd.getSheetName());
	Sheet currentSheet=this.currentWorkbook.getSheet(safeSheetName);
	if (currentSheet==null) {// create sheet if it does not exist yet
		currentSheet=this.currentWorkbook.createSheet(safeSheetName);
		if (!(safeSheetName.equals(sscd.getSheetName()))) {
			LOG.warn("Sheetname modified from \""+sscd.getSheetName()+"\" to \""+safeSheetName+"\" to correspond to Excel conventions.");
		}
		// create drawing anchor (needed for comments...)
		this.mappedDrawings.put(safeSheetName,currentSheet.createDrawingPatriarch());
	}
	// check if cell exist
	CellAddress currentCA = new CellAddress(sscd.getAddress());
	Row currentRow = currentSheet.getRow(currentCA.getRow());
	if (currentRow==null) { // row does not exist? => create it
		currentRow=currentSheet.createRow(currentCA.getRow());
	}
	Cell currentCell = currentRow.getCell(currentCA.getColumn());
	if ((currentCell!=null) && (this.hasTemplate==false)) { // cell already exists and no template loaded ? => throw exception
		throw new OfficeWriterException("Invalid cell specification: cell already exists at "+currentCA);
	}
	// create cell if no template is loaded or cell not available in template
	if ((this.hasTemplate==false) || (currentCell==null)) {
		currentCell=currentRow.createCell(currentCA.getColumn());		
	}
	// set the values accordingly
	if (!("".equals(sscd.getFormula()))) { // if formula exists then use formula
		currentCell.setCellFormula(sscd.getFormula());
		
	} else {	
	// else use formattedValue
		currentCell.setCellValue(sscd.getFormattedValue());
	}
	// set comment
	if ((sscd.getComment()!=null) && (!("".equals(sscd.getComment())))) {
		/** the following operations are necessary to create comments **/
		/** Define size of the comment window **/
		    ClientAnchor anchor = this.currentWorkbook.getCreationHelper().createClientAnchor();
    		    anchor.setCol1(currentCell.getColumnIndex());
    		    anchor.setCol2(currentCell.getColumnIndex()+this.howc.getCommentWidth());
    		    anchor.setRow1(currentRow.getRowNum());
    		    anchor.setRow2(currentRow.getRowNum()+this.howc.getCommentHeight());
		/** create comment **/
		    Comment currentComment = mappedDrawings.get(safeSheetName).createCellComment(anchor);
    		    currentComment.setString(this.currentWorkbook.getCreationHelper().createRichTextString(sscd.getComment()));
    		    currentComment.setAuthor(this.howc.getCommentAuthor());
		    currentCell.setCellComment(currentComment);

	}
}
 
开发者ID:ZuInnoTe,项目名称:hadoopoffice,代码行数:60,代码来源:MSExcelWriter.java

示例7: write

import org.apache.poi.ss.usermodel.ClientAnchor; //导入方法依赖的package包/类
@Override
public void write(Object newDAO) throws OfficeWriterException {
	SpreadSheetCellDAO sscd = MSExcelWriter.checkSpreadSheetCellDAO(newDAO);
	String safeSheetName=WorkbookUtil.createSafeSheetName(sscd.getSheetName());
	SXSSFSheet currentSheet=this.currentWorkbook.getSheet(safeSheetName);
	if (currentSheet==null) {// create sheet if it does not exist yet
		currentSheet=this.currentWorkbook.createSheet(safeSheetName);
		if (!(safeSheetName.equals(sscd.getSheetName()))) {
			LOG.warn("Sheetname modified from \""+sscd.getSheetName()+"\" to \""+safeSheetName+"\" to correspond to Excel conventions.");
		}
		// create drawing anchor (needed for comments...)
		this.mappedDrawings.put(safeSheetName,currentSheet.createDrawingPatriarch());
	}
	// check if cell exist
	CellAddress currentCA = new CellAddress(sscd.getAddress());
	SXSSFRow currentRow = currentSheet.getRow(currentCA.getRow());
	if (currentRow==null) { // row does not exist? => create it
		currentRow=currentSheet.createRow(currentCA.getRow());
	}
	SXSSFCell currentCell = currentRow.getCell(currentCA.getColumn());
	if ((currentCell!=null)) { // cell already exists and no template loaded ? => throw exception
		throw new OfficeWriterException("Invalid cell specification: cell already exists at "+currentCA);
	}
	// create cell if no template is loaded or cell not available in template
		currentCell=currentRow.createCell(currentCA.getColumn());		
	// set the values accordingly
	if (!("".equals(sscd.getFormula()))) { // if formula exists then use formula
		currentCell.setCellFormula(sscd.getFormula());
		
	} else {	
	// else use formattedValue
		currentCell.setCellValue(sscd.getFormattedValue());
	}
	// set comment
	if ((sscd.getComment()!=null) && (!("".equals(sscd.getComment())))) {
		/** the following operations are necessary to create comments **/
		/** Define size of the comment window **/
		    ClientAnchor anchor = this.currentWorkbook.getCreationHelper().createClientAnchor();
    		    anchor.setCol1(currentCell.getColumnIndex());
    		    anchor.setCol2(currentCell.getColumnIndex()+this.howc.getCommentWidth());
    		    anchor.setRow1(currentRow.getRowNum());
    		    anchor.setRow2(currentRow.getRowNum()+this.howc.getCommentHeight());
		/** create comment **/
		   Comment currentComment = mappedDrawings.get(safeSheetName).createCellComment(anchor);
    		    currentComment.setString(this.currentWorkbook.getCreationHelper().createRichTextString(sscd.getComment()));
    		    currentComment.setAuthor(this.howc.getCommentAuthor());
		    currentCell.setCellComment(currentComment);

	}
	}
 
开发者ID:ZuInnoTe,项目名称:hadoopoffice,代码行数:51,代码来源:MSExcelLowFootprintWriter.java

示例8: processCellImage

import org.apache.poi.ss.usermodel.ClientAnchor; //导入方法依赖的package包/类
/**
 * <p>
 * Process a CellImage from the images list and place the image on the sheet.
 * </p><p>
 * This involves changing the row height as necesssary and determining the column spread of the image.
 * </p>
 * @param cellImage
 * The image to be placed on the sheet.
 */
private void processCellImage( HandlerState state, Drawing drawing, CellImage cellImage ) {
	Coordinate location = cellImage.location;
	
	Cell cell = state.currentSheet.getRow( location.getRow() ).getCell( location.getCol() );

	IImageContent image = cellImage.image;		
	
	StyleManagerUtils smu = state.getSmu();
	float ptHeight = cell.getRow().getHeightInPoints();
	if( image.getHeight() != null ) {
		ptHeight = smu.fontSizeInPoints( image.getHeight().toString() );
	}

	// Get image width
	int endCol = cell.getColumnIndex();
       double lastColWidth = ClientAnchorConversions.widthUnits2Millimetres( (short)state.currentSheet.getColumnWidth( endCol ) )
       		+ 2.0;
       int dx = smu.anchorDxFromMM( lastColWidth, lastColWidth );
       double mmWidth = 0.0;
       if( smu.isAbsolute(image.getWidth())) {
           mmWidth = image.getWidth().convertTo(DimensionType.UNITS_MM);
       } else if(smu.isPixels(image.getWidth())) {
           mmWidth = ClientAnchorConversions.pixels2Millimetres( image.getWidth().getMeasure() );
       }
	// Allow image to span multiple columns
	CellRangeAddress mergedRegion = getMergedRegionBegunBy( state.currentSheet, location.getRow(), location.getCol() );
	if( (cellImage.spanColumns) || ( mergedRegion != null ) ) {
        log.debug( "Image size: ", image.getWidth(), " translates as mmWidth = ", mmWidth );
        if( mmWidth > 0) {
            double mmAccumulatedWidth = 0;
            int endColLimit = cellImage.spanColumns ? 256 : mergedRegion.getLastColumn();
            for( endCol = cell.getColumnIndex(); mmAccumulatedWidth < mmWidth && endCol < endColLimit; ++ endCol ) {
                lastColWidth = ClientAnchorConversions.widthUnits2Millimetres( (short)state.currentSheet.getColumnWidth( endCol ) )
                		+ 2.0;
                mmAccumulatedWidth += lastColWidth;
                log.debug( "lastColWidth = ", lastColWidth, "; mmAccumulatedWidth = ", mmAccumulatedWidth);
            }
            if( mmAccumulatedWidth > mmWidth ) {
                mmAccumulatedWidth -= lastColWidth;
                --endCol;
                double mmShort = mmWidth - mmAccumulatedWidth;
                dx = smu.anchorDxFromMM( mmShort, lastColWidth );
            }
        }
	} else {
		float widthRatio = (float)(mmWidth / lastColWidth);
		ptHeight = ptHeight / widthRatio;
	}

	int rowsSpanned = state.findRowsSpanned( cell.getRowIndex(), cell.getColumnIndex() );
	float neededRowHeightPoints = ptHeight;
	
	for( int i = 0; i < rowsSpanned; ++i ) {
		int rowIndex = cell.getRowIndex() + 1 + i;
		neededRowHeightPoints -= state.currentSheet.getRow(rowIndex).getHeightInPoints();
	}
	
	if( neededRowHeightPoints > cell.getRow().getHeightInPoints()) {
		cell.getRow().setHeightInPoints( neededRowHeightPoints );
	}
	
	// ClientAnchor anchor = wb.getCreationHelper().createClientAnchor();
	ClientAnchor anchor = state.getWb().getCreationHelper().createClientAnchor();
       anchor.setCol1(cell.getColumnIndex());
       anchor.setRow1(cell.getRowIndex());
       anchor.setCol2(endCol);
       anchor.setRow2(cell.getRowIndex() + rowsSpanned);
       anchor.setDx2(dx);
       anchor.setDy2( smu.anchorDyFromPoints( ptHeight, cell.getRow().getHeightInPoints() ) );
       anchor.setAnchorType(ClientAnchor.MOVE_DONT_RESIZE);
    drawing.createPicture(anchor, cellImage.imageIdx);
}
 
开发者ID:eclipse,项目名称:birt,代码行数:82,代码来源:PageHandler.java


注:本文中的org.apache.poi.ss.usermodel.ClientAnchor.setCol2方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。