]> source.dussan.org Git - poi.git/commitdiff
fixed compilation errors in recently added examples
authorYegor Kozlov <yegor@apache.org>
Mon, 15 Mar 2010 06:14:03 +0000 (06:14 +0000)
committerYegor Kozlov <yegor@apache.org>
Mon, 15 Mar 2010 06:14:03 +0000 (06:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@923072 13f79535-47bb-0310-9956-ffa450edef68

src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java
src/examples/src/org/apache/poi/ss/examples/AddDimensionedImage.java

index 9857725f529e9722f1aa646f1c2b6a2ca01527cf..6482f186c0d0be9da3639da0bbad5cb9835ab0f4 100644 (file)
@@ -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) {
index b7dc583add4b478cdd18e412d25e8af39132c3e5..6328739fd10b1c5d4bcf36f713b2bc06a5a8a77e 100644 (file)
@@ -24,7 +24,6 @@ import java.io.FileOutputStream;
 import java.io.IOException;\r
 import java.net.URL;\r
 \r
-import org.apache.commons.io.FilenameUtils;\r
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;\r
 import org.apache.poi.ss.usermodel.ClientAnchor;\r
 import org.apache.poi.ss.usermodel.Drawing;\r
@@ -250,8 +249,7 @@ public class AddDimensionedImage {
      */\r
     public void addImageToSheet(String cellNumber, Sheet sheet, Drawing drawing,\r
             URL imageFile, double reqImageWidthMM, double reqImageHeightMM,\r
-            int resizeBehaviour) throws FileNotFoundException, IOException,\r
-                                                      IllegalArgumentException {\r
+            int resizeBehaviour) throws IOException, IllegalArgumentException {\r
         // Convert the String into column and row indices then chain the\r
         // call to the overridden addImageToSheet() method.\r
         CellReference cellRef = new CellReference(cellNumber);\r
@@ -305,7 +303,7 @@ public class AddDimensionedImage {
      */\r
     public void addImageToSheet(int colNumber, int rowNumber, Sheet sheet, Drawing drawing,\r
             URL imageFile, double reqImageWidthMM, double reqImageHeightMM,\r
-            int resizeBehaviour) throws FileNotFoundException, IOException,\r
+            int resizeBehaviour) throws IOException,\r
                                                      IllegalArgumentException {\r
         ClientAnchor anchor = null;\r
         ClientAnchorDetail rowClientAnchorDetail = null;\r
@@ -365,11 +363,11 @@ public class AddDimensionedImage {
                        imageType = Workbook.PICTURE_TYPE_JPEG;\r
                }\r
                else  {\r
-                       throw new IllegalArgumentException("Invalid Image file extension: " +\r
-                               FilenameUtils.getExtension(sURL));\r
+                       throw new IllegalArgumentException("Invalid Image file : " +\r
+                               sURL);\r
                }\r
         int index = sheet.getWorkbook().addPicture(\r
-               IOUtils.toByteArray(imageFile.openStream()),type);\r
+               IOUtils.toByteArray(imageFile.openStream()), imageType);\r
         drawing.createPicture(anchor, index);\r
     }\r
 \r