org.apache.poi.xssf.usermodel.XSSFShape Java Examples

The following examples show how to use org.apache.poi.xssf.usermodel.XSSFShape. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PoiPublicUtil.java    From autopoi with Apache License 2.0 6 votes vote down vote up
/**
 * 获取Excel2007图片
 * 
 * @param sheet
 *            当前sheet对象
 * @param workbook
 *            工作簿对象
 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData
 */
public static Map<String, PictureData> getSheetPictrues07(XSSFSheet sheet, XSSFWorkbook workbook) {
	Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
	for (POIXMLDocumentPart dr : sheet.getRelations()) {
		if (dr instanceof XSSFDrawing) {
			XSSFDrawing drawing = (XSSFDrawing) dr;
			List<XSSFShape> shapes = drawing.getShapes();
			for (XSSFShape shape : shapes) {
				XSSFPicture pic = (XSSFPicture) shape;
				XSSFClientAnchor anchor = pic.getPreferredSize();
				CTMarker ctMarker = anchor.getFrom();
				String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();
				sheetIndexPicMap.put(picIndex, pic.getPictureData());
			}
		}
	}
	return sheetIndexPicMap;
}
 
Example #2
Source File: PoiPublicUtil.java    From jeasypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 获取Excel2007图片
 * 
 * @param sheet
 *            当前sheet对象
 * @param workbook
 *            工作簿对象
 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData
 */
public static Map<String, PictureData> getSheetPictrues07(XSSFSheet sheet, XSSFWorkbook workbook) {
	Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
	for (POIXMLDocumentPart dr : sheet.getRelations()) {
		if (dr instanceof XSSFDrawing) {
			XSSFDrawing drawing = (XSSFDrawing) dr;
			List<XSSFShape> shapes = drawing.getShapes();
			for (XSSFShape shape : shapes) {
				XSSFPicture pic = (XSSFPicture) shape;
				XSSFClientAnchor anchor = pic.getPreferredSize();
				CTMarker ctMarker = anchor.getFrom();
				String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();
				sheetIndexPicMap.put(picIndex, pic.getPictureData());
			}
		}
	}
	return sheetIndexPicMap;
}
 
Example #3
Source File: WatermarkExcelTests.java    From kbase-doc with Apache License 2.0 6 votes vote down vote up
@Test
public void testExcel() throws IOException {
	String filepath = "E:\\ConvertTester\\excel\\abcd.xlsx";
	File originFile = new File(filepath);
	InputStream in = new FileInputStream(originFile);
	XSSFWorkbook workbook = new XSSFWorkbook(in);
	XSSFSheet sheet = workbook.createSheet("testSheet");

	XSSFDrawing drawing = sheet.createDrawingPatriarch();
	
	XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 1023, 255, (short) 2, 4, (short) 13, 26);

	XSSFTextBox textbox = drawing.createTextbox(anchor);
	XSSFRichTextString rtxt = new XSSFRichTextString("ekozhan");
	XSSFFont font = workbook.createFont();
	font.setColor((short) 27);
	font.setBold(true);
	font.setFontHeightInPoints((short) 192);
	font.setFontName("Verdana");
	rtxt.applyFont(font);
	textbox.setText(rtxt);
	textbox.setLineStyle(XSSFShape.EMU_PER_POINT);
	textbox.setNoFill(true);
	workbook.write(new FileOutputStream(filepath));
	workbook.close();
}
 
Example #4
Source File: PoiPublicUtil.java    From easypoi with Apache License 2.0 6 votes vote down vote up
/**
 * 获取Excel2007图片
 * 
 * @param sheet
 *            当前sheet对象
 * @param workbook
 *            工作簿对象
 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData
 */
public static Map<String, PictureData> getSheetPictrues07(XSSFSheet sheet, XSSFWorkbook workbook) {
    Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();
    for (POIXMLDocumentPart dr : sheet.getRelations()) {
        if (dr instanceof XSSFDrawing) {
            XSSFDrawing drawing = (XSSFDrawing) dr;
            List<XSSFShape> shapes = drawing.getShapes();
            for (XSSFShape shape : shapes) {
                XSSFPicture pic = (XSSFPicture) shape;
                XSSFClientAnchor anchor = pic.getPreferredSize();
                CTMarker ctMarker = anchor.getFrom();
                String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();
                sheetIndexPicMap.put(picIndex, pic.getPictureData());
            }
        }
    }
    return sheetIndexPicMap;
}
 
Example #5
Source File: ExcelPublicUtil.java    From jeewx with Apache License 2.0 6 votes vote down vote up
/** 
 * 获取Excel2007图片 
 * @param sheet 当前sheet对象
 * @param workbook 工作簿对象 
 * @return Map key:图片单元格索引(1_1)String,value:图片流PictureData 
 */  
public static Map<String, PictureData> getSheetPictrues07(  
        XSSFSheet sheet, XSSFWorkbook workbook) {  
    Map<String, PictureData> sheetIndexPicMap = new HashMap<String, PictureData>();  
    for (POIXMLDocumentPart dr : sheet.getRelations()) {  
        if (dr instanceof XSSFDrawing) {  
            XSSFDrawing drawing = (XSSFDrawing) dr;  
            List<XSSFShape> shapes = drawing.getShapes();  
            for (XSSFShape shape : shapes) {  
                XSSFPicture pic = (XSSFPicture) shape;  
                XSSFClientAnchor anchor = pic.getPreferredSize();  
                CTMarker ctMarker = anchor.getFrom();  
                String picIndex = ctMarker.getRow() + "_" + ctMarker.getCol();  
                sheetIndexPicMap.put(picIndex, pic.getPictureData());  
            }  
        }  
    }  
    return sheetIndexPicMap;  
}
 
Example #6
Source File: Prd3278IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testImageAligningToCellsXLSX() {
  TableRectangle rect = new TableRectangle();
  rect.setRect( 1, 1, 2, 2 );
  StrictBounds b =
      new StrictBounds( StrictGeomUtility.toInternalValue( 100 ), StrictGeomUtility.toInternalValue( 100 ),
          StrictGeomUtility.toInternalValue( 400 ), StrictGeomUtility.toInternalValue( 400 ) );
  ClientAnchor clientAnchor = xlsxImageHandler.computeClientAnchor( sheetLayout, rect, b );
  Assert.assertEquals( 1, clientAnchor.getCol1() );
  Assert.assertEquals( 1, clientAnchor.getCol2() );
  Assert.assertEquals( 1, clientAnchor.getRow1() );
  Assert.assertEquals( 1, clientAnchor.getRow2() );

  Assert.assertEquals( 0, clientAnchor.getDx1() );
  Assert.assertEquals( 400 * XSSFShape.EMU_PER_POINT, clientAnchor.getDx2() );
  Assert.assertEquals( 0, clientAnchor.getDy1() );
  Assert.assertEquals( 400 * XSSFShape.EMU_PER_POINT, clientAnchor.getDy2() );
}
 
Example #7
Source File: Prd3278IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testImageAligningLeftAndTopXLSX() {
  TableRectangle rect = new TableRectangle();
  rect.setRect( 1, 1, 2, 2 );
  StrictBounds b =
      new StrictBounds( StrictGeomUtility.toInternalValue( 100 ), StrictGeomUtility.toInternalValue( 100 ),
          StrictGeomUtility.toInternalValue( 300 ), StrictGeomUtility.toInternalValue( 300 ) );

  ClientAnchor clientAnchor = xlsxImageHandler.computeClientAnchor( sheetLayout, rect, b );
  Assert.assertEquals( 1, clientAnchor.getCol1() );
  Assert.assertEquals( 1, clientAnchor.getCol2() );
  Assert.assertEquals( 1, clientAnchor.getRow1() );
  Assert.assertEquals( 1, clientAnchor.getRow2() );

  Assert.assertEquals( 0, clientAnchor.getDx1() );
  Assert.assertEquals( 300 * XSSFShape.EMU_PER_POINT, clientAnchor.getDx2() );
  Assert.assertEquals( 0, clientAnchor.getDy1() );
  Assert.assertEquals( 300 * XSSFShape.EMU_PER_POINT, clientAnchor.getDy2() );
}
 
Example #8
Source File: Prd3278IT.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testImageAligningMiddleXLSX() {
  TableRectangle rect = new TableRectangle();
  rect.setRect( 1, 1, 2, 2 );
  StrictBounds b =
      new StrictBounds( StrictGeomUtility.toInternalValue( 200 ), StrictGeomUtility.toInternalValue( 200 ),
          StrictGeomUtility.toInternalValue( 200 ), StrictGeomUtility.toInternalValue( 200 ) );

  ClientAnchor clientAnchor = xlsxImageHandler.computeClientAnchor( sheetLayout, rect, b );
  Assert.assertEquals( 1, clientAnchor.getCol1() );
  Assert.assertEquals( 1, clientAnchor.getCol2() );
  Assert.assertEquals( 1, clientAnchor.getRow1() );
  Assert.assertEquals( 1, clientAnchor.getRow2() );

  Assert.assertEquals( 100 * XSSFShape.EMU_PER_POINT, clientAnchor.getDx1() );
  Assert.assertEquals( 300 * XSSFShape.EMU_PER_POINT, clientAnchor.getDx2() );
  Assert.assertEquals( 100 * XSSFShape.EMU_PER_POINT, clientAnchor.getDy1() );
  Assert.assertEquals( 300 * XSSFShape.EMU_PER_POINT, clientAnchor.getDy2() );
}
 
Example #9
Source File: ExcelImageHandler.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected ClientAnchor computeExcel2003ClientAnchor( final SlimSheetLayout currentLayout,
    final TableRectangle rectangle, final StrictBounds cb ) {
  final int cell1x = rectangle.getX1();
  final int cell1y = rectangle.getY1();
  final int cell2x = Math.max( cell1x, rectangle.getX2() - 1 );
  final int cell2y = Math.max( cell1y, rectangle.getY2() - 1 );

  final long cell1xPos = currentLayout.getXPosition( cell1x );
  final long cell1yPos = currentLayout.getYPosition( cell1y );
  final long cell2xPos = currentLayout.getXPosition( cell2x );
  final long cell2yPos = currentLayout.getYPosition( cell2y );

  final int dx1 = (int) StrictGeomUtility.toExternalValue( ( cb.getX() - cell1xPos ) * XSSFShape.EMU_PER_POINT );
  final int dy1 = (int) StrictGeomUtility.toExternalValue( ( cb.getY() - cell1yPos ) * XSSFShape.EMU_PER_POINT );
  final int dx2 =
      (int) Math.max( 0, StrictGeomUtility.toExternalValue( ( cb.getX() + cb.getWidth() - cell2xPos )
          * XSSFShape.EMU_PER_POINT ) );
  final int dy2 =
      (int) Math.max( 0, StrictGeomUtility.toExternalValue( ( cb.getY() + cb.getHeight() - cell2yPos )
          * XSSFShape.EMU_PER_POINT ) );

  final ClientAnchor anchor = printerBase.getWorkbook().getCreationHelper().createClientAnchor();
  anchor.setDx1( dx1 );
  anchor.setDy1( dy1 );
  anchor.setDx2( dx2 );
  anchor.setDy2( dy2 );
  anchor.setCol1( cell1x );
  anchor.setRow1( cell1y );
  anchor.setCol2( cell2x );
  anchor.setRow2( cell2y );
  anchor.setAnchorType( ClientAnchor.AnchorType.MOVE_DONT_RESIZE );
  return anchor;
}
 
Example #10
Source File: StyleManagerXUtils.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public int anchorDyFromPoints( float height, float rowHeight ) {
	return (int)( height * XSSFShape.EMU_PER_POINT );
}