gnopaste

gnopaste database reset @ 19/03/2013

Name
Stimpy
Scriptlanguage
Java
Tabwidth
4
Date
05/31/2013 11:08:52 am
IP
::ffff:217.247.215.210

Method to add images to regions of an excel sheet.

  1. private HSSFSheet insertUnscaledImageWithFilename(Workbook workbook, HSSFSheet sheet, int col, int row, int col2, int row2, String fileName)
  2.     {
  3.         try
  4.         {
  5.             StringBuilder builder = new StringBuilder(45);
  6.             builder.append(Configuration.getRoot().getInstallation().getDirectory());
  7.             builder.append(File.separator).append(Configuration.getRoot().getInstallation().getPortalName());
  8.             builder.append(File.separator).append(IMAGE_PATH);
  9.             builder.append(File.separator).append(fileName);
  10.             InputStream is = new FileInputStream(builder.toString());
  11.             byte[] bytes = IOUtils.toByteArray(is);
  12.             int pictureIdx = workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
  13.             CreationHelper helper = workbook.getCreationHelper();
  14.             Drawing drawing = sheet.createDrawingPatriarch();
  15.             ClientAnchor anchor = helper.createClientAnchor();
  16.             anchor.setCol1(col);
  17.             anchor.setRow1(row);
  18.             anchor.setCol2(col2);
  19.             anchor.setRow2(row2);
  20.             anchor.setAnchorType(2);
  21.             Picture pict = drawing.createPicture(anchor, pictureIdx);
  22.         }
  23.         catch (FileNotFoundException fnfe)
  24.         {
  25.             System.out.println("FileNotFoundException:" + fnfe.getMessage());
  26.         }
  27.         catch (IOException ioe)
  28.         {
  29.             System.out.println("IOException:" + ioe.getMessage());
  30.         }
  31.         return sheet;
  32.     }
submitter » gnopaster | imprint « imprint     
» Terms of use «