String imageFile, double reqImageWidthMM, double reqImageHeightMM,
int resizeBehaviour) throws FileNotFoundException, IOException,
IllegalArgumentException {
- HSSFRow row = null;
HSSFClientAnchor anchor = null;
HSSFPatriarch patriarch = null;
ClientAnchorDetail rowClientAnchorDetail = null;
public static void main(String[] args) {
String imageFile = null;
String outputFile = null;
- FileInputStream fis = null;
FileOutputStream fos = null;
HSSFWorkbook workbook = null;
HSSFSheet sheet = null;
ioEx.printStackTrace(System.out);
}
finally {
- if(fos != null) {
- try {
+ try {
+ if (workbook != null) {
+ workbook.close();
+ }
+ } catch(IOException ioEx) {
+ // I G N O R E
+ }
+ try {
+ if(fos != null) {
fos.close();
fos = null;
}
- catch(IOException ioEx) {
- // I G N O R E
- }
+ } catch(IOException ioEx) {
+ // I G N O R E
}
}
}
int pixels = (widthUnits / EXCEL_COLUMN_WIDTH_FACTOR)
* UNIT_OFFSET_LENGTH;
int offsetWidthUnits = widthUnits % EXCEL_COLUMN_WIDTH_FACTOR;
- pixels += Math.round((float) offsetWidthUnits /
+ pixels += Math.round(offsetWidthUnits /
((float) EXCEL_COLUMN_WIDTH_FACTOR / UNIT_OFFSET_LENGTH));
return pixels;
}
Row row = sheet.getRow(i - sheet.getFirstRowNum());
if (row != null) {
short h = row.getHeight();
- int height = (int)Math.round(Math.max(1., ((double)h) / (((double)res) / 70. * 20.) + 3.));
+ int height = (int)Math.round(Math.max(1., h / (res / 70. * 20.) + 3.));
System.out.printf("%d: %d (%d @ %d)%n", i, height, h, res);
setRowHeight(i, height);
}
package org.apache.poi.hssf.view;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.*;
-
-import javax.swing.*;
-import javax.swing.table.*;
-
-import org.apache.poi.hssf.usermodel.*;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.util.EventObject;
+import java.util.Map;
+
+import javax.swing.AbstractCellEditor;
+import javax.swing.JTable;
+import javax.swing.JTextField;
+import javax.swing.SwingConstants;
+import javax.swing.table.TableCellEditor;
+
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFCellStyle;
+import org.apache.poi.hssf.usermodel.HSSFFont;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
/**
private HSSFWorkbook wb;
private JTextField editor;
- private HSSFCell editorValue;
-
-
public SVTableCellEditor(HSSFWorkbook wb) {
this.wb = wb;
this.editor = new JTextField();
*
*/
private final Color getAWTColor(int index, Color deflt) {
- HSSFColor clr = (HSSFColor)colors.get(Integer.valueOf(index));
+ HSSFColor clr = colors.get(index);
if (clr == null) return deflt;
return getAWTColor(clr);
}
* @return The aWTColor value
*/
public final static Color getAWTColor(int index, Color deflt) {
- HSSFColor clr = (HSSFColor) colors.get(Integer.valueOf(index));
+ HSSFColor clr = colors.get(index);
if (clr == null) {
return deflt;
}
final String fsName,
final MutableTreeNode root)
{
- MutableTreeNode n = (MutableTreeNode) pathToNode.get(path);
+ MutableTreeNode n = pathToNode.get(path);
if (n != null)
/* Node found in map, just return it. */
return n;
* the POI filesystem itself. This is a tree node with the
* POI filesystem's name (this the operating system file's
* name) as its key it the path-to-node map. */
- n = (MutableTreeNode) pathToNode.get(fsName);
+ n = pathToNode.get(fsName);
if (n == null)
{
/* A tree node for the POI filesystem does not yet
public static void main(String[] args) throws FileNotFoundException, IOException, InvalidFormatException {
XSSFWorkbook wb = new XSSFWorkbook();
- XSSFSheet sheet = (XSSFSheet) wb.createSheet();
+ XSSFSheet sheet = wb.createSheet();
//Create some data to build the pivot table on
setCellData(sheet);
FileOutputStream fileOut = new FileOutputStream("ooxml-pivottable.xlsx");
wb.write(fileOut);
fileOut.close();
+ wb.close();
}
public static void setCellData(XSSFSheet sheet){
rec.formatting_options = formatting_options;
rec.formatting_not_used = formatting_not_used;
if (containsFontFormattingBlock()) {
- rec._fontFormatting = (FontFormatting) _fontFormatting.clone();
+ rec._fontFormatting = _fontFormatting.clone();
}
if (containsBorderFormattingBlock()) {
- rec._borderFormatting = (BorderFormatting) _borderFormatting.clone();
+ rec._borderFormatting = _borderFormatting.clone();
}
if (containsPatternFormattingBlock()) {
rec._patternFormatting = (PatternFormatting) _patternFormatting.clone();
rec.options = options;
rec.percentMin = percentMin;
rec.percentMax = percentMax;
- rec.color = (ExtendedColor)color.clone();
- rec.thresholdMin = (DataBarThreshold)thresholdMin.clone();
- rec.thresholdMax = (DataBarThreshold)thresholdMax.clone();
+ rec.color = color.clone();
+ rec.thresholdMin = thresholdMin.clone();
+ rec.thresholdMax = thresholdMax.clone();
return rec;
}
* \r
*/\r
public void setVal(byte[] value) {\r
- this.val = ((byte[]) value);\r
+ this.val = (value != null) ? value.clone() : null;\r
}\r
\r
public boolean isSetVal() {\r
* \r
*/\r
public void setLastClr(byte[] value) {\r
- this.lastClr = ((byte[]) value);\r
+ this.lastClr = (value != null) ? value.clone() : null;\r
}\r
\r
public boolean isSetLastClr() {\r
* @return a SimpleFraction with the given values set.
*/
public static SimpleFraction buildFractionExactDenominator(double val, int exactDenom){
- int num = (int)Math.round(val*(double)exactDenom);
+ int num = (int)Math.round(val*exactDenom);
return new SimpleFraction(num,exactDenom);
}
package org.apache.poi.xssf.streaming;
-import java.io.IOException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
-import junit.framework.TestCase;
+import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.Test;
-public final class TestOutlining extends TestCase {
- public void testSetRowGroupCollapsed() throws Exception {
+public final class TestOutlining {
+ @Test
+ public void testSetRowGroupCollapsed() throws IOException {
SXSSFWorkbook wb2 = new SXSSFWorkbook(100);
wb2.setCompressTempFiles(true);
- SXSSFSheet sheet2 = (SXSSFSheet) wb2.createSheet("new sheet");
+ SXSSFSheet sheet2 = wb2.createSheet("new sheet");
int rowCount = 20;
for (int i = 0; i < rowCount; i++) {
sheet2.setRowGroupCollapsed(4, true);
- SXSSFRow r = (SXSSFRow) sheet2.getRow(8);
+ SXSSFRow r = sheet2.getRow(8);
assertTrue(r.getHidden());
- r = (SXSSFRow) sheet2.getRow(10);
+ r = sheet2.getRow(10);
assertTrue(r.getCollapsed());
- r = (SXSSFRow) sheet2.getRow(12);
+ r = sheet2.getRow(12);
assertNull(r.getHidden());
wb2.dispose();
wb2.close();
}
- public void testSetRowGroupCollapsedError() throws Exception {
+ @Test
+ public void testSetRowGroupCollapsedError() throws IOException {
SXSSFWorkbook wb2 = new SXSSFWorkbook(100);
wb2.setCompressTempFiles(true);
- SXSSFSheet sheet2 = (SXSSFSheet) wb2.createSheet("new sheet");
+ SXSSFSheet sheet2 = wb2.createSheet("new sheet");
int rowCount = 20;
for (int i = 0; i < rowCount; i++) {
e.getMessage().contains("Row does not exist"));
}
- SXSSFRow r = (SXSSFRow) sheet2.getRow(8);
+ SXSSFRow r = sheet2.getRow(8);
assertNotNull(r);
assertNull(r.getHidden());
- r = (SXSSFRow) sheet2.getRow(10);
+ r = sheet2.getRow(10);
assertNull(r.getCollapsed());
- r = (SXSSFRow) sheet2.getRow(12);
+ r = sheet2.getRow(12);
assertNull(r.getHidden());
wb2.dispose();
wb2.close();
}
+ @Test
public void testOutlineGettersHSSF() throws IOException {
HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
HSSFSheet hssfSheet = hssfWorkbook.createSheet();
hssfWorkbook.close();
}
+ @Test
public void testOutlineGettersXSSF() throws IOException {
XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
XSSFSheet xssfSheet = xssfWorkbook.createSheet();
xssfWorkbook.close();
}
+ @Test
public void testOutlineGettersSXSSF() throws IOException {
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
Sheet sxssfSheet = sxssfWorkbook.createSheet();
sxssfWorkbook.close();
}
+ @Test
public void testOutlineGettersSXSSFSetOutlineLevel() throws IOException {
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
Sheet sxssfSheet = sxssfWorkbook.createSheet();
* @deprecated Use {@link #OldSectionTable(byte[],int,int)} instead
*/
@Deprecated
- @SuppressWarnings( "unused" )
public OldSectionTable( byte[] documentStream, int offset, int size,
int fcMin, TextPieceTable tpt )
{
* {@link #PAPBinTable(byte[], byte[], byte[], int, int, CharIndexTranslator)}
* instead
*/
- @SuppressWarnings( "unused" )
public PAPBinTable( byte[] documentStream, byte[] tableStream,
byte[] dataStream, int offset, int size, int fcMin,
TextPieceTable tpt )
\r
if ( _fExtend )\r
{\r
- LittleEndian.putUShort( buffer, offset, (int) entry.length() );\r
+ LittleEndian.putUShort( buffer, offset, entry.length() );\r
offset += LittleEndian.SHORT_SIZE;\r
\r
StringUtil.putUnicodeLE( entry, buffer, offset );\r
LittleEndian.putInt(data, 0x8 + offset, field_3_yaTop);\r
LittleEndian.putInt(data, 0xc + offset, field_4_xaRight);\r
LittleEndian.putInt(data, 0x10 + offset, field_5_yaBottom);\r
- LittleEndian.putShort(data, 0x14 + offset, (short)field_6_flags);\r
+ LittleEndian.putShort(data, 0x14 + offset, field_6_flags);\r
LittleEndian.putInt(data, 0x16 + offset, field_7_cTxbx);\r
}\r
\r
// Ensure they match
assertEquals(allTheText.length,foundTextV.size());
for(int i=0; i<allTheText.length; i++) {
- String foundText = (String)foundTextV.get(i);
+ String foundText = foundTextV.get(i);
assertEquals(allTheText[i],foundText);
}
}
package org.apache.poi.hwpf.usermodel;
-import java.util.List;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
-import junit.framework.TestCase;
+import java.util.List;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.PicturesTable;
+import org.junit.Test;
/**
* Test the picture handling
*
* @author Nick Burch
*/
-public final class TestPictures extends TestCase {
+public final class TestPictures {
/**
* two jpegs
*/
+ @Test
public void testTwoImages() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("two_images.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures();
assertNotNull(pics);
assertEquals(pics.size(), 2);
for(int i=0; i<pics.size(); i++) {
- Picture pic = (Picture)pics.get(i);
+ Picture pic = pics.get(i);
assertNotNull(pic.suggestFileExtension());
assertNotNull(pic.suggestFullFileName());
}
Picture picA = pics.get(0);
Picture picB = pics.get(1);
assertEquals("jpg", picA.suggestFileExtension());
- assertEquals("jpg", picA.suggestFileExtension());
+ assertEquals("png", picB.suggestFileExtension());
}
/**
* pngs and jpegs
*/
+ @Test
public void testDifferentImages() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("testPictures.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures();
assertNotNull(pics);
assertEquals(7, pics.size());
- for(int i=0; i<pics.size(); i++) {
- Picture pic = (Picture)pics.get(i);
+ for(Picture pic : pics) {
assertNotNull(pic.suggestFileExtension());
assertNotNull(pic.suggestFullFileName());
}
/**
* emf image, nice and simple
*/
+ @Test
public void testEmfImage() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("vector_image.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures();
}
}
- public void testPicturesWithTable() {
+ @Test
+ public void testPicturesWithTable() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44603.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures();
assertEquals(2, pics.size());
}
- public void testPicturesInHeader() {
+ @Test
+ public void testPicturesInHeader() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("header_image.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures();
assertEquals(2, pics.size());
}
+ @Test
public void testFastSaved() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("rasp.doc");
doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
}
+ @Test
public void testFastSaved2() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("o_kurs.doc");
doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
}
+ @Test
public void testFastSaved3() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ob_is.doc");
* then used as-is to speed things up.
* Check that we can properly read one of these
*/
- public void testEmbededDocumentIcon() throws Exception {
+ @Test
+ public void testEmbededDocumentIcon() {
// This file has two embeded excel files, an embeded powerpoint
// file and an embeded word file, in that order
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("word_with_embeded.doc");
assertEquals( "image/x-emf", picture.getMimeType() );
}
+ @Test
public void testEquation()
{
HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "equation.doc" );
* \u0001 which has the offset. More than one can
* reference the same \u0001
*/
- public void testFloatingPictures() throws Exception {
+ @Test
+ public void testFloatingPictures() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("FloatingPictures.doc");
PicturesTable pictures = doc.getPicturesTable();
}
@SuppressWarnings( "deprecation" )
+ @Test
public void testCroppedPictures() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("testCroppedPictures.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures();
assertEquals(0, pic2.getDyaCropBottom());
}
- public void testPictureDetectionWithPNG() throws Exception {
+ @Test
+ public void testPictureDetectionWithPNG() {
HWPFDocument document = HWPFTestDataSamples.openSampleFile("PngPicture.doc");
PicturesTable pictureTable = document.getPicturesTable();
assertEquals("png", p.suggestFileExtension());
}
- public void testPictureWithAlternativeText() throws Exception {
+ @Test
+ public void testPictureWithAlternativeText() {
HWPFDocument document = HWPFTestDataSamples.openSampleFile("Picture_Alternative_Text.doc");
PicturesTable pictureTable = document.getPicturesTable();
Picture picture = pictureTable.getAllPictures().get(0);
package org.apache.poi.hwpf.usermodel;
-import junit.framework.TestCase;
-
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.PAPX;
+import junit.framework.TestCase;
+
/**
* Test to see if Range.delete() works even if the Range contains a
* CharacterRun that uses Unicode characters.
assertEquals(fillerText, para.text());
- paraDef = (PAPX)daDoc.getParagraphTable().getParagraphs().get(2);
+ paraDef = daDoc.getParagraphTable().getParagraphs().get(2);
assertEquals(132, paraDef.getStart());
assertEquals(400, paraDef.getEnd());
assertEquals(originalText, para.text());
- paraDef = (PAPX)daDoc.getParagraphTable().getParagraphs().get(3);
+ paraDef = daDoc.getParagraphTable().getParagraphs().get(3);
assertEquals(400, paraDef.getStart());
assertEquals(438, paraDef.getEnd());
PropertySet ps = PropertySetFactory.create(new ByteArrayInputStream(bytes));
DocumentSummaryInformation dsi = (DocumentSummaryInformation) ps;
- Section s = (Section) dsi.getSections().get(0);
+ Section s = dsi.getSections().get(0);
Object hdrs = s.getProperty(PropertyIDMap.PID_HEADINGPAIR);
record.setNumEntries((short)3);
byte[] src = record.serialize();
- AutoFilterInfoRecord cloned = (AutoFilterInfoRecord)record.clone();
+ AutoFilterInfoRecord cloned = record.clone();
assertEquals(3, record.getNumEntries());
byte[] cln = cloned.serialize();
CFRuleRecord record = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5");
- CFRuleRecord clone = (CFRuleRecord) record.clone();
+ CFRuleRecord clone = record.clone();
byte [] serializedRecord = record.serialize();
byte [] serializedClone = clone.serialize();
FtCblsSubRecord record = new FtCblsSubRecord();
byte[] src = record.serialize();
- FtCblsSubRecord cloned = (FtCblsSubRecord)record.clone();
+ FtCblsSubRecord cloned = record.clone();
byte[] cln = cloned.serialize();
assertEquals(record.getDataSize(), cloned.getDataSize());
for (int i = 0; i < data.length; i++) {
RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, data[i]);
HyperlinkRecord link = new HyperlinkRecord(is);
- HyperlinkRecord clone = (HyperlinkRecord)link.clone();
+ HyperlinkRecord clone = link.clone();
assertArrayEquals(link.serialize(), clone.serialize());
}
public void testCloneReferences() {
CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2), };
MergeCellsRecord merge = new MergeCellsRecord(cras, 0, cras.length);
- MergeCellsRecord clone = (MergeCellsRecord)merge.clone();
+ MergeCellsRecord clone = merge.clone();
assertNotSame("Merged and cloned objects are the same", merge, clone);
record.setShapeId((short)1026);
record.setAuthor("Apache Software Foundation");
- NoteRecord cloned = (NoteRecord)record.clone();
+ NoteRecord cloned = record.clone();
assertEquals(record.getRow(), cloned.getRow());
assertEquals(record.getColumn(), cloned.getColumn());
assertEquals(record.getFlags(), cloned.getFlags());
NoteStructureSubRecord record = new NoteStructureSubRecord();
byte[] src = record.serialize();
- NoteStructureSubRecord cloned = (NoteStructureSubRecord)record.clone();
+ NoteStructureSubRecord cloned = record.clone();
byte[] cln = cloned.serialize();
assertEquals(record.getDataSize(), cloned.getDataSize());
}
else
{
- copy = new OPOIFSDocument(
- "test" + input.length,
- ( SmallDocumentBlock [] ) document.getSmallBlocks(),
- input.length);
+ copy = new OPOIFSDocument("test"+input.length, document.getSmallBlocks(), input.length);
}
return copy;
}
*/
package org.apache.poi.ss.formula.functions;
-import java.lang.reflect.Constructor;
-
import org.apache.poi.ss.formula.functions.XYNumericFunction.Accumulator;
assertEquals(0.0, MathX.mod(0, 2));
assertEquals(Double.NaN, MathX.mod(3, 0));
- assertEquals((double) 1.4, MathX.mod(3.4, 2));
- assertEquals((double) -1.4, MathX.mod(-3.4, -2));
- assertEquals((double) 0.6000000000000001, MathX.mod(-3.4, 2.0));// should actually be 0.6
- assertEquals((double) -0.6000000000000001, MathX.mod(3.4, -2.0));// should actually be -0.6
+ assertEquals(1.4, MathX.mod(3.4, 2));
+ assertEquals(-1.4, MathX.mod(-3.4, -2));
+ assertEquals(0.6000000000000001, MathX.mod(-3.4, 2.0));// should actually be 0.6
+ assertEquals(-0.6000000000000001, MathX.mod(3.4, -2.0));// should actually be -0.6
assertEquals(3.0, MathX.mod(3, Double.MAX_VALUE));
assertEquals(2.0, MathX.mod(Double.MAX_VALUE, 3));