try {\r
//read the image using javax.imageio.*\r
ImageInputStream iis = ImageIO.createImageInputStream( is );\r
- Iterator<ImageReader> i = ImageIO.getImageReaders( iis );\r
- ImageReader r = i.next();\r
- r.setInput( iis );\r
- BufferedImage img = r.read(0);\r
-\r
- int[] dpi = getResolution(r);\r
-\r
- //if DPI is zero then assume standard 96 DPI\r
- //since cannot divide by zero\r
- if (dpi[0] == 0) dpi[0] = PIXEL_DPI;\r
- if (dpi[1] == 0) dpi[1] = PIXEL_DPI;\r
-\r
- size.width = img.getWidth()*PIXEL_DPI/dpi[0];\r
- size.height = img.getHeight()*PIXEL_DPI/dpi[1];\r
-\r
- r.dispose();\r
- iis.close();\r
-\r
- } catch (IOException e){\r
+ try {\r
+ Iterator<ImageReader> i = ImageIO.getImageReaders( iis );\r
+ ImageReader r = i.next();\r
+ try {\r
+ r.setInput( iis );\r
+ BufferedImage img = r.read(0);\r
+ \r
+ int[] dpi = getResolution(r);\r
+ \r
+ //if DPI is zero then assume standard 96 DPI\r
+ //since cannot divide by zero\r
+ if (dpi[0] == 0) dpi[0] = PIXEL_DPI;\r
+ if (dpi[1] == 0) dpi[1] = PIXEL_DPI;\r
+ \r
+ size.width = img.getWidth()*PIXEL_DPI/dpi[0];\r
+ size.height = img.getHeight()*PIXEL_DPI/dpi[1];\r
+ } finally {\r
+ r.dispose();\r
+ }\r
+ } finally {\r
+ iis.close();\r
+ }\r
+\r
+ } catch (IOException e) {\r
//silently return if ImageIO failed to read the image\r
logger.log(POILogger.WARN, e);\r
}\r
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.CellReference;
-import org.apache.poi.ss.util.RegionUtil;
import org.apache.poi.util.TempFile;
import org.apache.poi.xssf.XLSBUnsupportedException;
import org.apache.poi.xssf.XSSFITestDataProvider;
throw new AssertionFailedError("expected (c='" + colStr + "', r='" + rowStr + "' to be "
+ (expResult ? "within" : "out of") + " bounds for version " + sv.name());
}
+
+ public void testConvertColStringToIndex() {
+ assertEquals(0, CellReference.convertColStringToIndex("A"));
+ assertEquals(1, CellReference.convertColStringToIndex("B"));
+ assertEquals(14, CellReference.convertColStringToIndex("O"));
+ assertEquals(701, CellReference.convertColStringToIndex("ZZ"));
+ assertEquals(18252, CellReference.convertColStringToIndex("ZZA"));
+
+ assertEquals(0, CellReference.convertColStringToIndex("$A"));
+ assertEquals(1, CellReference.convertColStringToIndex("$B"));
+
+ try {
+ CellReference.convertColStringToIndex("A$");
+ fail("Should throw exception here");
+ } catch (IllegalArgumentException e) {
+ assertTrue(e.getMessage().contains("A$"));
+ }
+ }
+
+ public void testConvertNumColColString() {
+ assertEquals("A", CellReference.convertNumToColString(0));
+ assertEquals("AV", CellReference.convertNumToColString(47));
+ assertEquals("AW", CellReference.convertNumToColString(48));
+ assertEquals("BF", CellReference.convertNumToColString(57));
+
+ assertEquals("", CellReference.convertNumToColString(-1));
+ assertEquals("", CellReference.convertNumToColString(Integer.MIN_VALUE));
+ assertEquals("", CellReference.convertNumToColString(Integer.MAX_VALUE));
+ assertEquals("FXSHRXW", CellReference.convertNumToColString(Integer.MAX_VALUE-1));
+ }
}