本文整理了Java中org.apache.poi.ss.usermodel.Drawing.createPicture()
方法的一些代码示例,展示了Drawing.createPicture()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Drawing.createPicture()
方法的具体详情如下:
包路径:org.apache.poi.ss.usermodel.Drawing
类名称:Drawing
方法名:createPicture
[英]Creates a picture.
[中]创建一张图片。
代码示例来源:origin: youseries/ureport
anchor.setDy1(0 * XSSFShape.EMU_PER_PIXEL);
anchor.setDy2(height * XSSFShape.EMU_PER_PIXEL);
drawing.createPicture(anchor, pictureIndex);
}finally{
IOUtils.closeQuietly(inputStream);
anchor.setDy1(0 * XSSFShape.EMU_PER_PIXEL);
anchor.setDy2(height * XSSFShape.EMU_PER_PIXEL);
drawing.createPicture(anchor, pictureIndex);
}finally{
IOUtils.closeQuietly(inputStream);
anchor.setDy1(0 * XSSFShape.EMU_PER_PIXEL);
anchor.setDy2(height * XSSFShape.EMU_PER_PIXEL);
drawing.createPicture(anchor, pictureIndex);
}finally{
IOUtils.closeQuietly(inputStream);
anchor.setDy1(0 * XSSFShape.EMU_PER_PIXEL);
anchor.setDy2(height * XSSFShape.EMU_PER_PIXEL);
drawing.createPicture(anchor, pictureIndex);
}finally{
IOUtils.closeQuietly(inputStream);
代码示例来源:origin: youseries/ureport
anchor.setDy1(topMargin * XSSFShape.EMU_PER_PIXEL);
anchor.setDy2(height * XSSFShape.EMU_PER_PIXEL);
drawing.createPicture(anchor, pictureIndex);
}finally{
IOUtils.closeQuietly(inputStream);
anchor.setDy1(topMargin * XSSFShape.EMU_PER_PIXEL);
anchor.setDy2(height * XSSFShape.EMU_PER_PIXEL);
drawing.createPicture(anchor, pictureIndex);
}finally{
IOUtils.closeQuietly(inputStream);
代码示例来源:origin: youseries/ureport
anchor.setDy1(topMargin * XSSFShape.EMU_PER_PIXEL);
anchor.setDy2(height * XSSFShape.EMU_PER_PIXEL);
drawing.createPicture(anchor, pictureIndex);
}finally{
IOUtils.closeQuietly(inputStream);
anchor.setDy1(topMargin * XSSFShape.EMU_PER_PIXEL);
anchor.setDy2(height * XSSFShape.EMU_PER_PIXEL);
drawing.createPicture(anchor, pictureIndex);
}finally{
IOUtils.closeQuietly(inputStream);
代码示例来源:origin: stackoverflow.com
FileInputStream fis = new FileInputStream(imagePath);
int b;
byte[] bytes = IOUtils.toByteArray(fis);
fis.close();
// This will insert the picture from start cell to end cell of excel
// sheet.
HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0,
start.getCol(), start.getRow(), end.getCol(), end.getRow());
anchor.setAnchorType(2);
int index = wb.addPicture(bytes, HSSFWorkbook.PICTURE_TYPE_JPEG);
// Create the drawing patriarch. This is the top level container for all shapes.
Drawing patriarch = sheet.createDrawingPatriarch();
try {
HSSFPicture picture = patriarch.createPicture(anchor, index);
// picture.resize();
} catch (Exception e) {
String err = e.getMessage();
}
代码示例来源:origin: stackoverflow.com
anchor.setRow1(2);
drawing.createPicture(anchor, pictureureIdx);
代码示例来源:origin: stackoverflow.com
LOGO_MARGIN = 2;
int index = getLogoPictureIndex();
CreationHelper helper = this.wb.getCreationHelper();
Drawing drawing = this.sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setDx1(LOGO_MARGIN * XSSFShape.EMU_PER_PIXEL);
anchor.setDy1(LOGO_MARGIN * XSSFShape.EMU_PER_PIXEL);
Picture pic = drawing.createPicture(anchor, index);
pic.resize(0.064);
代码示例来源:origin: stackoverflow.com
CreationHelper helper = wb.getCreationHelper();
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setDx1(LOGO_MARGIN * XSSFShape.EMU_PER_PIXEL);
anchor.setDx2(LOGO_WIDTH_IN_FUNNY_POI_FORMAT * XSSFShape.EMU_PER_PIXEL);
anchor.setDy1(LOGO_MARGIN * XSSFShape.EMU_PER_PIXEL);
anchor.setDy2(LOGO_HEIGHT_IN_FUNNY_POI_FORMAT * XSSFShape.EMU_PER_PIXEL);
drawing.createPicture(anchor, pictureIndex);
代码示例来源:origin: stackoverflow.com
final FileInputStream stream =
new FileInputStream( "C:/Users/Administrator/Desktop/New folder/Excel/Jellyfish.jpg" );
final CreationHelper helper = workbook.getCreationHelper();
final Drawing drawing = sheet.createDrawingPatriarch();
final ClientAnchor anchor = helper.createClientAnchor();
anchor.setAnchorType( ClientAnchor.MOVE_AND_RESIZE );
final int pictureIndex =
workbook.addPicture( stream, Workbook.PICTURE_TYPE_JPEG );
anchor.setCol1( 0 );
anchor.setRow1( LOGO_ROW ); // same row is okay
anchor.setRow2( LOGO_ROW );
anchor.setCol2( 1 );
final Picture pict = drawing.createPicture( anchor, pictureIndex );
pict.resize();
代码示例来源:origin: stackoverflow.com
// read the image to the stream
final FileInputStream stream =
new FileInputStream( imagePath );
final CreationHelper helper = workbook.getCreationHelper();
final Drawing drawing = sheet.createDrawingPatriarch();
final ClientAnchor anchor = helper.createClientAnchor();
anchor.setAnchorType( ClientAnchor.MOVE_AND_RESIZE );
final int pictureIndex =
workbook.addPicture( stream, Workbook.PICTURE_TYPE_PNG );
anchor.setCol1( 0 );
anchor.setRow1( LOGO_ROW ); // same row is okay
anchor.setRow2( LOGO_ROW );
anchor.setCol2( 1 );
final Picture pict = drawing.createPicture( anchor, pictureIndex );
pict.resize();
代码示例来源:origin: stackoverflow.com
Workbook resultWorkbook = transformer.transformXLS(is, beans);
Iterator rowIter = resultWorkbook.getSheetAt(0).rowIterator();
while (rowIter.hasNext()){
HSSFRow row = (HSSFRow) rowIter.next();
Iterator cellIter = row.cellIterator();
while (cellIter.hasNext()){
HSSFCell cell = (HSSFCell) cellIter.next();
final String IMG_PREFIX = "#IMG#";
if(cell.toString().startsWith(IMG_PREFIX)){
String cellValue = cell.toString();
cell.setCellValue("");
String imagePath = cellValue.replaceFirst(IMG_PREFIX, "");
File imageFile = new File(imagePath);
if(imageFile.exists()){
FileInputStream isi = new FileInputStream(imageFile);
ImageTools imageTools = new ImageTools();
byte[] imgBytes = imageTools.resizeImage(isi, 100);
int pictureIdx = resultWorkbook.addPicture(imgBytes, Workbook.PICTURE_TYPE_JPEG);
CreationHelper helper = resultWorkbook.getCreationHelper();
Drawing drawing = resultWorkbook.getSheetAt(0).createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(cell.getColumnIndex());
anchor.setRow1(cell.getRowIndex());
Picture pict = drawing.createPicture(anchor, pictureIdx);
pict.resize();
isi.close();
}
}
}
}
代码示例来源:origin: zhangdaiscott/jeasypoi
ImageIO.write(bufferImg, imagePath.substring(imagePath.indexOf(".") + 1, imagePath.length()), byteArrayOut);
byte[] value = byteArrayOut.toByteArray();
patriarch.createPicture(anchor, row.getSheet().getWorkbook().addPicture(value, getImageType(value)));
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
byte[] value = (byte[]) (entity.getMethods() != null ? getFieldBySomeMethod(entity.getMethods(), obj) : entity.getMethod().invoke(obj, new Object[] {}));
if (value != null) {
patriarch.createPicture(anchor, row.getSheet().getWorkbook().addPicture(value, getImageType(value)));
代码示例来源:origin: org.apache.poi/poi-examples
anchor.setCol1(1);
anchor.setRow1(1);
Picture pict = drawing.createPicture(anchor, pictureIdx);
代码示例来源:origin: stackoverflow.com
Picture pict = drawing.createPicture(anchor, pictureIdx);
代码示例来源:origin: GZWgssmart/zywork
/**
* 在指定工作表的指定位置插入图片
* @param sheet 工作表
* @param imagePath 图片路径
* @param beginRow 图片开始的行
* @param beginCol 图片开始的列
*/
public void insertPicture(Sheet sheet, String imagePath,
int beginRow, int beginCol) {
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor clientAnchor = workbook.getCreationHelper().createClientAnchor();
clientAnchor.setRow1(beginRow);
clientAnchor.setCol1(beginCol);
Picture picture = drawing.createPicture(clientAnchor,
workbook.addPicture(ImageUtils.getImageData(imagePath), getImageType(imagePath)));
picture.resize();
}
代码示例来源:origin: GZWgssmart/zywork
/**
* 在指定工作表的指定位置插入图片
* @param sheet 工作表
* @param imageInputStream 图片输入流
* @param imageType 图片文件类型枚举,推荐使用png或jpg图片
* @param beginRow 图片开始的行
* @param beginCol 图片开始的列
*/
public void insertPicture(Sheet sheet, InputStream imageInputStream, MIMETypeEnum imageType,
int beginRow, int beginCol) {
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor clientAnchor = workbook.getCreationHelper().createClientAnchor();
clientAnchor.setRow1(beginRow);
clientAnchor.setCol1(beginCol);
Picture picture = drawing.createPicture(clientAnchor,
workbook.addPicture(ImageUtils.getImageData(imageInputStream, imageType), getImageType(imageType)));
picture.resize();
}
代码示例来源:origin: org.jeecg/easypoi-base
patriarch.createPicture(anchor,
row.getSheet().getWorkbook().addPicture(value, getImageType(value)));
代码示例来源:origin: org.jxls/jxls-poi
private void addImage(AreaRef areaRef, int imageIdx) {
CreationHelper helper = workbook.getCreationHelper();
Sheet sheet = workbook.getSheet(areaRef.getSheetName());
if(sheet == null) {
sheet = workbook.createSheet(areaRef.getSheetName());
}
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = helper.createClientAnchor();
anchor.setCol1(areaRef.getFirstCellRef().getCol());
anchor.setRow1(areaRef.getFirstCellRef().getRow());
anchor.setCol2(areaRef.getLastCellRef().getCol());
anchor.setRow2(areaRef.getLastCellRef().getRow());
drawing.createPicture(anchor, imageIdx);
}
代码示例来源:origin: GZWgssmart/zywork
/**
* 在指定工作表的指定位置插入图片
* @param sheet 工作表
* @param imagePath 图片路径
* @param leftDX 图片在单元格中离左上角的x距离
* @param topDY 图片在单元格中离左上角的y距离
* @param widthDX 图片的宽度
* @param heightDY 图片的高度
* @param beginRow 图片开始的行
* @param beginCol 图片开始的列
* @param endRow 图片结束的行
* @param endCol 图片结束的列
*/
public void insertPicture(Sheet sheet, String imagePath,
int leftDX, int topDY, int widthDX ,int heightDY,
int beginRow, int beginCol, int endRow, int endCol) {
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor clientAnchor = workbook.getCreationHelper().createClientAnchor();
clientAnchor.setDx1(leftDX);
clientAnchor.setDy1(topDY);
clientAnchor.setDx2(widthDX);
clientAnchor.setDy2(heightDY);
clientAnchor.setRow1(beginRow);
clientAnchor.setCol1(beginCol);
clientAnchor.setRow2(endRow);
clientAnchor.setCol2(endCol);
drawing.createPicture(clientAnchor,
workbook.addPicture(ImageUtils.getImageData(imagePath), getImageType(imagePath)));
}
代码示例来源:origin: GZWgssmart/zywork
/**
* 在指定工作表的指定位置插入图片
* @param sheet 工作表
* @param imageInputStream 图片输入流
* @param imageType 图片文件类型枚举,推荐使用png或jpg图片
* @param leftDX 图片在单元格中离左上角的x距离
* @param topDY 图片在单元格中离左上角的y距离
* @param widthDX 图片的宽度
* @param heightDY 图片的高度
* @param beginRow 图片开始的行
* @param beginCol 图片开始的列
* @param endRow 图片结束的行
* @param endCol 图片结束的列
*/
public void insertPicture(Sheet sheet, InputStream imageInputStream, MIMETypeEnum imageType,
int leftDX, int topDY, int widthDX ,int heightDY,
int beginRow, int beginCol, int endRow, int endCol) {
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor clientAnchor = workbook.getCreationHelper().createClientAnchor();
clientAnchor.setDx1(leftDX);
clientAnchor.setDy1(topDY);
clientAnchor.setDx2(widthDX);
clientAnchor.setDy2(heightDY);
clientAnchor.setRow1(beginRow);
clientAnchor.setCol1(beginCol);
clientAnchor.setRow2(endRow);
clientAnchor.setCol2(endCol);
drawing.createPicture(clientAnchor,
workbook.addPicture(ImageUtils.getImageData(imageInputStream, imageType), getImageType(imageType)));
}
代码示例来源:origin: cn.afterturn/easypoi-base
/**
* 图片类型的Cell
*/
public void createImageCell(Cell cell, double height,
String imagePath, byte[] data) throws Exception {
if (height > cell.getRow().getHeight()) {
cell.getRow().setHeight((short) height);
}
ClientAnchor anchor;
if (type.equals(ExcelType.HSSF)) {
anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
cell.getRow().getRowNum() + 1);
} else {
anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), cell.getRow().getRowNum(), (short) (cell.getColumnIndex() + 1),
cell.getRow().getRowNum() + 1);
}
if (StringUtils.isNotEmpty(imagePath)) {
data = ImageCache.getImage(imagePath);
}
if (data != null) {
PoiExcelGraphDataUtil.getDrawingPatriarch(cell.getSheet()).createPicture(anchor,
cell.getSheet().getWorkbook().addPicture(data, getImageType(data)));
}
}
内容来源于网络,如有侵权,请联系作者删除!