diff options
author | Yegor Kozlov <yegor@apache.org> | 2008-11-12 07:15:37 +0000 |
---|---|---|
committer | Yegor Kozlov <yegor@apache.org> | 2008-11-12 07:15:37 +0000 |
commit | fadd255a55a4613466b21e97c06bb85947a4b7f1 (patch) | |
tree | 71b46a586c739b1a0c34b35d2d81a3ba95999f84 /src/documentation | |
parent | 8987da6f67c7f0480dd7f090ad9eb0830ee7e130 (diff) | |
download | poi-fadd255a55a4613466b21e97c06bb85947a4b7f1.tar.gz poi-fadd255a55a4613466b21e97c06bb85947a4b7f1.zip |
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
Diffstat (limited to 'src/documentation')
-rw-r--r-- | src/documentation/content/xdocs/spreadsheet/quick-guide.xml | 64 |
1 files changed, 23 insertions, 41 deletions
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. </p> - <p><strong>HSSF:</strong></p> <source> - // 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 )); - </source> - <p>Creating an image and setting its anchor to the actual width and height:</p> - <source> - HSSFPatriarch patriarch = sheet5.createDrawingPatriarch(); - - HSSFPicture picture = patriarch.createPicture(new HSSFClientAnchor(), loadPicture( "src/resources/logos/logoKarmokar4.png", wb )); - picture.resize(); - </source> - <p>or</p> - <source> - HSSFPatriarch patriarch = sheet5.createDrawingPatriarch(); - - HSSFPicture picture = patriarch.createPicture(new HSSFClientAnchor(), loadPicture( "src/resources/logos/logoKarmokar4.png", wb )); - HSSFClientAnchor preferredSize = picture.getPreferredSize(); - picture.setAnchor(preferredSize); - </source> - <p><strong>XSSF:</strong></p> - <source> //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(); - </source> + </source> <warning> - 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. </warning> - <p>Reading images from a workbook:</p> <source> |