From: Yegor Kozlov Date: Mon, 15 Mar 2010 06:14:03 +0000 (+0000) Subject: fixed compilation errors in recently added examples X-Git-Tag: REL_3_7_BETA1~104 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a0925a6320e7350efef98d2347b9993657158764;p=poi.git fixed compilation errors in recently added examples git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@923072 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java index 9857725f52..6482f186c0 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java @@ -198,8 +198,7 @@ public class AddDimensionedImage { */ public void addImageToSheet(String cellNumber, HSSFSheet sheet, String imageFile, double reqImageWidthMM, double reqImageHeightMM, - int resizeBehaviour) throws FileNotFoundException, IOException, - IllegalArgumentException { + int resizeBehaviour) throws IOException, IllegalArgumentException { // Convert the String into column and row indices then chain the // call to the overridden addImageToSheet() method. CellReference cellRef = new CellReference(cellNumber); @@ -500,7 +499,6 @@ public class AddDimensionedImage { double colWidthMM = 0.0D; double overlapMM = 0.0D; double coordinatePositionsPerMM = 0.0D; - int fromNumber = startingColumn; int toColumn = startingColumn; int inset = 0; @@ -558,7 +556,7 @@ public class AddDimensionedImage { // Next, from the columns width, calculate how many co-ordinate // positons there are per millimetre - coordinatePositionsPerMM = ExcelUtil.TOTAL_COLUMN_COORDINATE_POSITIONS / + coordinatePositionsPerMM = ConvertImageUnits.TOTAL_COLUMN_COORDINATE_POSITIONS / colWidthMM; // From this figure, determine how many co-ordinat positions to // inset the left hand or bottom edge of the image. @@ -673,8 +671,7 @@ public class AddDimensionedImage { * @throws java.io.IOException Thrown if reading the file failed or was * interrupted. */ - private byte[] imageToBytes(String imageFilename) - throws FileNotFoundException, IOException { + private byte[] imageToBytes(String imageFilename) throws IOException { File imageFile = null; FileInputStream fis = null; ByteArrayOutputStream bos = null; @@ -721,18 +718,26 @@ public class AddDimensionedImage { * @param args the command line arguments */ public static void main(String[] args) { - File file = null; + String imageFile = null; + String outputFile = null; FileInputStream fis = null; FileOutputStream fos = null; HSSFWorkbook workbook = null; HSSFSheet sheet = null; try { + if(args.length < 2){ + System.err.println("Usage: AddDimensionedImage imageFile outputFile"); + return; + } + imageFile = args[0]; + outputFile = args[1]; + workbook = new HSSFWorkbook(); sheet = workbook.createSheet("Picture Test"); new AddDimensionedImage().addImageToSheet("A1", sheet, - "C:/temp/1.png", 25, 25, + imageFile, 125, 125, AddDimensionedImage.EXPAND_ROW_AND_COLUMN); - fos = new FileOutputStream("C:/temp/Newly Auto Adjusted.xls"); + fos = new FileOutputStream(outputFile); workbook.write(fos); } catch(FileNotFoundException fnfEx) { diff --git a/src/examples/src/org/apache/poi/ss/examples/AddDimensionedImage.java b/src/examples/src/org/apache/poi/ss/examples/AddDimensionedImage.java index b7dc583add..6328739fd1 100644 --- a/src/examples/src/org/apache/poi/ss/examples/AddDimensionedImage.java +++ b/src/examples/src/org/apache/poi/ss/examples/AddDimensionedImage.java @@ -24,7 +24,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; -import org.apache.commons.io.FilenameUtils; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.ClientAnchor; import org.apache.poi.ss.usermodel.Drawing; @@ -250,8 +249,7 @@ public class AddDimensionedImage { */ public void addImageToSheet(String cellNumber, Sheet sheet, Drawing drawing, URL imageFile, double reqImageWidthMM, double reqImageHeightMM, - int resizeBehaviour) throws FileNotFoundException, IOException, - IllegalArgumentException { + int resizeBehaviour) throws IOException, IllegalArgumentException { // Convert the String into column and row indices then chain the // call to the overridden addImageToSheet() method. CellReference cellRef = new CellReference(cellNumber); @@ -305,7 +303,7 @@ public class AddDimensionedImage { */ public void addImageToSheet(int colNumber, int rowNumber, Sheet sheet, Drawing drawing, URL imageFile, double reqImageWidthMM, double reqImageHeightMM, - int resizeBehaviour) throws FileNotFoundException, IOException, + int resizeBehaviour) throws IOException, IllegalArgumentException { ClientAnchor anchor = null; ClientAnchorDetail rowClientAnchorDetail = null; @@ -365,11 +363,11 @@ public class AddDimensionedImage { imageType = Workbook.PICTURE_TYPE_JPEG; } else { - throw new IllegalArgumentException("Invalid Image file extension: " + - FilenameUtils.getExtension(sURL)); + throw new IllegalArgumentException("Invalid Image file : " + + sURL); } int index = sheet.getWorkbook().addPicture( - IOUtils.toByteArray(imageFile.openStream()),type); + IOUtils.toByteArray(imageFile.openStream()), imageType); drawing.createPicture(anchor, index); }