From fadd255a55a4613466b21e97c06bb85947a4b7f1 Mon Sep 17 00:00:00 2001
From: Yegor Kozlov
Date: Wed, 12 Nov 2008 07:15:37 +0000
Subject: common ss interfaces for drawing, clientacnhor and picture, also some
refactoring of common hssf-xssf code
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@713279 13f79535-47bb-0310-9956-ffa450edef68
---
.../content/xdocs/spreadsheet/quick-guide.xml | 64 ++++++++--------------
1 file changed, 23 insertions(+), 41 deletions(-)
(limited to 'src/documentation')
diff --git a/src/documentation/content/xdocs/spreadsheet/quick-guide.xml b/src/documentation/content/xdocs/spreadsheet/quick-guide.xml
index 461a5f207f..9b347c7592 100644
--- a/src/documentation/content/xdocs/spreadsheet/quick-guide.xml
+++ b/src/documentation/content/xdocs/spreadsheet/quick-guide.xml
@@ -1163,63 +1163,45 @@ Examples:
It should be noted that any existing drawings may be erased
once you add a image to a sheet.
-
HSSF:
- // Create the drawing patriarch. This is the top level container for
- // all shapes. This will clear out any existing shapes for that sheet.
- HSSFPatriarch patriarch = sheet5.createDrawingPatriarch();
-
- HSSFClientAnchor anchor;
- anchor = new HSSFClientAnchor(0,0,0,255,(short)2,2,(short)4,7);
- anchor.setAnchorType( 2 );
- patriarch.createPicture(anchor, loadPicture( "src/resources/logos/logoKarmokar4.png", wb ));
-
-
Creating an image and setting its anchor to the actual width and height:
-
//create a new workbook
- XSSFWorkbook wb = new XSSFWorkbook();
+ Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
- //add a picture in this workbook.
- InputStream is = new FileInputStream("lilies.jpg");
- int pictureIdx = wb.addPicture(is, XSSFWorkbook.PICTURE_TYPE_JPEG);
+ //add picture data to this workbook.
+ InputStream is = new FileInputStream("image1.jpeg");
+ byte[] bytes = IOUtils.toByteArray(is);
+ int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close();
+ CreationHelper helper = wb.getCreationHelper();
+
//create sheet
- XSSFSheet sheet = wb.createSheet();
+ Sheet sheet = wb.createSheet();
- //create drawing
- XSSFDrawing drawing = sheet.createDrawingPatriarch();
+ // Create the drawing patriarch. This is the top level container for all shapes.
+ Drawing drawing = sheet.createDrawingPatriarch();
//add a picture shape
- XSSFPicture pict = drawing.createPicture(new XSSFClientAnchor(), pictureIdx);
-
- //auto-size picture
+ ClientAnchor anchor = helper.createClientAnchor();
+ //set top-left corner of the picture,
+ //subsequent call of Picture#resize() will operate relative to it
+ anchor.setCol1(3);
+ anchor.setRow1(2);
+ Picture pict = drawing.createPicture(anchor, pictureIdx);
+
+ //auto-size picture relative to its top-left corner
pict.resize();
//save workbook
- FileOutputStream fileOut = new FileOutputStream("xssf-picture.xlsx");
+ String file = "picture.xls";
+ if(wb instanceof XSSFWorkbook) file += "x";
+ FileOutputStream fileOut = new FileOutputStream(file);
wb.write(fileOut);
fileOut.close();
-
+
- HSSFPicture.resize() and XSSFPicture.resize() work only for JPEG and PNG. Other formats are not yet supported.
+ Picture.resize() works only for JPEG and PNG. Other formats are not yet supported.
-