import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord;
import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord;
import org.apache.poi.hssf.record.BOFRecord;
-import org.apache.poi.hssf.record.BlankRecord;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.MulBlankRecord;
import org.apache.poi.hssf.record.MulRKRecord;
import org.apache.poi.hssf.record.NoteRecord;
-import org.apache.poi.hssf.record.NumberRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordFactory;
import org.apache.poi.hssf.record.RowRecord;
*/
public final class MissingRecordAwareHSSFListener implements HSSFListener {
private HSSFListener childListener;
-
+
// Need to have different counters for cell rows and
// row rows, as you sometimes get a RowRecord in the
// middle of some cells, and that'd break everything
private int lastRowRow;
-
+
private int lastCellRow;
private int lastCellColumn;
-
+
/**
* Constructs a new MissingRecordAwareHSSFListener, which
* will fire processRecord on the supplied child
break;
}
}
-
+
// First part of expanded record handling
if(expandedRecords != null && expandedRecords.length > 0) {
thisRow = expandedRecords[0].getRow();
thisColumn = expandedRecords[0].getColumn();
}
-
+
// If we're on cells, and this cell isn't in the same
- // row as the last one, then fire the
+ // row as the last one, then fire the
// dummy end-of-row records
if(thisRow != lastCellRow && lastCellRow > -1) {
for(int i=lastCellRow; i<thisRow; i++) {
childListener.processRecord(new LastCellOfRowDummyRecord(i, cols));
}
}
-
+
// If we've just finished with the cells, then fire the
// final dummy end-of-row record
if(lastCellRow != -1 && lastCellColumn != -1 && thisRow == -1) {
childListener.processRecord(new LastCellOfRowDummyRecord(lastCellRow, lastCellColumn));
-
+
lastCellRow = -1;
lastCellColumn = -1;
}
-
+
// If we've moved onto a new row, the ensure we re-set
// the column counter
if(thisRow != lastCellRow) {
lastCellColumn = -1;
}
-
+
// If there's a gap in the cells, then fire
// the dummy cell records
if(lastCellColumn != thisColumn-1) {
childListener.processRecord(new MissingCellDummyRecord(thisRow, i));
}
}
-
+
// Next part of expanded record handling
if(expandedRecords != null && expandedRecords.length > 0) {
thisColumn = expandedRecords[expandedRecords.length-1].getColumn();
}
-
+
// Update cell and row counts as needed
if(thisColumn != -1) {
lastCellColumn = thisColumn;
package org.apache.poi.hssf.usermodel;
+import java.awt.Dimension;
+import java.io.ByteArrayInputStream;
+
import org.apache.poi.ddf.EscherBSERecord;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
import org.apache.poi.ss.usermodel.Picture;
import org.apache.poi.ss.util.ImageUtils;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
-import javax.imageio.stream.ImageInputStream;
-import java.awt.image.BufferedImage;
-import java.awt.*;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.Iterator;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
/**
* Represents a escher picture. Eg. A GIF, JPEG etc...
private int _pictureIndex;
HSSFPatriarch _patriarch; // TODO make private
- private static final POILogger log = POILogFactory.getLogger(HSSFPicture.class);
-
/**
* Constructs a picture object.
*/
package org.apache.poi.ss.util;
import org.apache.poi.ss.SpreadsheetVersion;
-import org.apache.poi.ss.usermodel.Cell;
/**
package org.apache.poi.ddf;
-import java.io.File;
-import java.io.FileInputStream;
import java.util.List;
import junit.framework.TestCase;
-import org.apache.poi.util.HexRead;
-import org.apache.poi.util.HexDump;
-import org.apache.poi.util.IOUtils;
+
import org.apache.poi.POIDataSamples;
+import org.apache.poi.util.HexDump;
+import org.apache.poi.util.HexRead;
/**
* Tests for {@link EscherContainerRecord}
import org.apache.poi.hpsf.CustomProperties;
import org.apache.poi.hpsf.DocumentSummaryInformation;
-import org.apache.poi.hpsf.MarkUnsupportedException;
-import org.apache.poi.hpsf.NoPropertySetStreamException;
import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.SummaryInformation;
-import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
import org.apache.poi.hpsf.WritingNotSupportedException;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DocumentEntry;
}
- /**
+ /**
* Iterative testing of the unicode test
- *
+ *
*/
public void testSix() {
for (int i = 1; i < 100; i++) {
package org.apache.poi.hpsf.extractor;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import junit.framework.TestCase;
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.POIDataSamples;
public final class TestHPSFPropertiesExtractor extends TestCase {
- private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
+ private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
public void testNormalProperties() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(
- _samples.openResourceAsStream("TestMickey.doc")
- );
+ POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream("TestMickey.doc"));
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
ext.getText();
}
public void testNormalUnicodeProperties() throws Exception {
- POIFSFileSystem fs = new POIFSFileSystem(
- _samples.openResourceAsStream("TestUnicode.xls")
- );
+ POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream("TestUnicode.xls"));
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
ext.getText();
public void testCustomProperties() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(
- _samples.openResourceAsStream("TestMickey.doc")
- );
+ _samples.openResourceAsStream("TestMickey.doc")
+ );
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
// Custom properties are part of the document info stream
POIFSFileSystem fs;
HSSFWorkbook wb;
try {
- fs = new POIFSFileSystem(
- _samples.openResourceAsStream("TestUnicode.xls")
- );
+ fs = new POIFSFileSystem(_samples.openResourceAsStream("TestUnicode.xls"));
wb = new HSSFWorkbook(fs);
} catch (IOException e) {
throw new RuntimeException(e);
package org.apache.poi.hssf.extractor;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import junit.framework.TestCase;
+import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
-import org.apache.poi.POIDataSamples;
/**
*
* Excel embeded in excel
*/
public void testWithEmbededInOwn() throws Exception {
- POIDataSamples ssSamples = POIDataSamples.getSpreadSheetInstance();
+ POIDataSamples ssSamples = POIDataSamples.getSpreadSheetInstance();
POIFSFileSystem fs = new POIFSFileSystem(
- ssSamples.openResourceAsStream("excel_with_embeded.xls")
- );
+ ssSamples.openResourceAsStream("excel_with_embeded.xls")
+ );
DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B5");
DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B4");
package org.apache.poi.hssf.record;
-import junit.framework.TestCase;
-
-import java.util.Arrays;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+import org.apache.poi.hssf.record.formula.AreaPtg;
+import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.HexRead;
-import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianInputStream;
import org.apache.poi.util.LittleEndianOutputStream;
-import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.hssf.record.formula.AreaPtg;
-import org.apache.poi.ss.util.CellRangeAddress;
/**
* Tests the serialization and deserialization of the LbsDataSubRecord class works correctly.
assertTrue(Arrays.equals(data, baos.toByteArray()));
}
-}
\ No newline at end of file
+}
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.functions.Offset.LinearOffsetRange;
/**
import java.util.Date;
import java.util.GregorianCalendar;
-import java.io.FileOutputStream;
import junit.framework.AssertionFailedError;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.StringRecord;
+import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.BaseTestCell;
import org.apache.poi.ss.usermodel.ErrorConstants;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.SpreadsheetVersion;
/**
* Tests various functionality having to do with {@link HSSFCell}. For instance support for
* @author Alex Jacoby (ajacoby at gmail.com)
*/
public final class TestHSSFCell extends BaseTestCell {
-
+
private static final HSSFITestDataProvider _hssfDP = HSSFITestDataProvider.getInstance();
-
+
public TestHSSFCell() {
super(HSSFITestDataProvider.getInstance());
}
assertEquals("Date from file using 1900 Date Windowing",
date.getTime(),
sheet.getRow(0).getCell(0).getDateCellValue().getTime());
-
+
// now check a file with 1904 Date Windowing
workbook = _hssfDP.openSampleWorkbook("1904DateWindowing.xls");
sheet = workbook.getSheetAt(0);
// first check a file with 1900 Date Windowing
HSSFWorkbook wb;
wb = _hssfDP.openSampleWorkbook("1900DateWindowing.xls");
-
+
setCell(wb, 0, 1, date);
wb = _hssfDP.writeOutAndReadBack(wb);
-
+
assertEquals("Date from file using 1900 Date Windowing",
date.getTime(),
readCell(wb, 0, 1).getTime());
-
+
// now check a file with 1904 Date Windowing
wb = _hssfDP.openSampleWorkbook("1904DateWindowing.xls");
- setCell(wb, 0, 1, date);
+ setCell(wb, 0, 1, date);
wb = _hssfDP.writeOutAndReadBack(wb);
assertEquals("Date from file using 1900 Date Windowing",
date.getTime(),
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFRow row = sheet.getRow(rowIdx);
HSSFCell cell = row.getCell(colIdx);
-
+
if (cell == null) {
cell = row.createCell(colIdx);
}
cell.setCellValue(date);
}
-
+
private static Date readCell(HSSFWorkbook workbook, int rowIdx, int colIdx) {
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFRow row = sheet.getRow(rowIdx);
HSSFCell cell = row.getCell(colIdx);
return cell.getDateCellValue();
}
-
+
/**
* Tests that the active cell can be correctly read and set
*/
public void testActiveCell() {
//read in sample
HSSFWorkbook book = _hssfDP.openSampleWorkbook("Simple.xls");
-
+
//check initial position
HSSFSheet umSheet = book.getSheetAt(0);
Sheet s = umSheet.getSheet();
(short) 0, s.getActiveCellCol());
assertEquals("Initial active cell should be on row 1",
1, s.getActiveCellRow());
-
+
//modify position through HSSFCell
HSSFCell cell = umSheet.createRow(3).createCell(2);
cell.setAsActiveCell();
(short) 2, s.getActiveCellCol());
assertEquals("After modify, active cell should be on row 3",
3, s.getActiveCellRow());
-
+
//write book to temp file; read and verify that position is serialized
book = _hssfDP.writeOutAndReadBack(book);
umSheet = book.getSheetAt(0);
s = umSheet.getSheet();
-
+
assertEquals("After serialize, active cell should be in col 2",
(short) 2, s.getActiveCellCol());
assertEquals("After serialize, active cell should be on row 3",
assertEquals(4, link.getFirstRow());
assertEquals(0, link.getFirstColumn());
}
-
+
/**
* Test reading hyperlinks
*/
public void testWithTwoHyperlinks() {
HSSFWorkbook wb = _hssfDP.openSampleWorkbook("WithTwoHyperLinks.xls");
-
+
HSSFSheet sheet = wb.getSheetAt(0);
HSSFCell cell1 = sheet.getRow(4).getCell(0);
/**
* Test for small bug observable around r736460 (prior to version 3.5). POI fails to remove
- * the {@link StringRecord} following the {@link FormulaRecord} after the result type had been
+ * the {@link StringRecord} following the {@link FormulaRecord} after the result type had been
* changed to number/boolean/error. Excel silently ignores the extra record, but some POI
* versions (prior to bug 46213 / r717883) crash instead.
*/
throw new AssertionFailedError("Identified bug - leftover StringRecord");
}
confirmStringRecord(sheet, false);
-
+
// string to error code
cell.setCellValue("abc");
confirmStringRecord(sheet, true);
cell.setCellErrorValue((byte)ErrorConstants.ERROR_REF);
confirmStringRecord(sheet, false);
-
+
// string to boolean
cell.setCellValue("abc");
confirmStringRecord(sheet, true);
assertEquals(DBCellRecord.class, dbcr.getClass());
}
- /**
- * The maximum length of cell contents (text) is 32,767 characters.
- */
- public void testMaxTextLength(){
- HSSFSheet sheet = new HSSFWorkbook().createSheet();
- HSSFCell cell = sheet.createRow(0).createCell(0);
-
- int maxlen = SpreadsheetVersion.EXCEL97.getMaxTextLength();
- assertEquals(32767, maxlen);
-
- StringBuffer b = new StringBuffer() ;
-
- // 32767 is okay
- for( int i = 0 ; i < maxlen ; i++ )
- {
- b.append( "X" ) ;
- }
- cell.setCellValue(b.toString());
-
- b.append("X");
- // 32768 produces an invalid XLS file
- try {
- cell.setCellValue(b.toString());
- fail("Expected exception");
- } catch (IllegalArgumentException e){
- assertEquals("The maximum length of cell contents (text) is 32,767 characters", e.getMessage());
- }
- }
-}
+ /**
+ * The maximum length of cell contents (text) is 32,767 characters.
+ */
+ public void testMaxTextLength(){
+ HSSFSheet sheet = new HSSFWorkbook().createSheet();
+ HSSFCell cell = sheet.createRow(0).createCell(0);
+ int maxlen = SpreadsheetVersion.EXCEL97.getMaxTextLength();
+ assertEquals(32767, maxlen);
+
+ StringBuffer b = new StringBuffer() ;
+
+ // 32767 is okay
+ for( int i = 0 ; i < maxlen ; i++ )
+ {
+ b.append( "X" ) ;
+ }
+ cell.setCellValue(b.toString());
+
+ b.append("X");
+ // 32768 produces an invalid XLS file
+ try {
+ cell.setCellValue(b.toString());
+ fail("Expected exception");
+ } catch (IllegalArgumentException e){
+ assertEquals("The maximum length of cell contents (text) is 32,767 characters", e.getMessage());
+ }
+ }
+}
package org.apache.poi.poifs.filesystem;
import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import junit.framework.TestCase;
-import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.POIDataSamples;
+import org.apache.poi.hssf.HSSFTestDataSamples;
/**
* Tests for POIFSFileSystem
- *
+ *
* @author Josh Micich
*/
public final class TestPOIFSFileSystem extends TestCase {
}
/**
* Helps facilitate testing. Keeps track of whether close() was called.
- * Also can throw an exception at a specific point in the stream.
+ * Also can throw an exception at a specific point in the stream.
*/
private static final class TestIS extends InputStream {
return _isClosed;
}
}
-
+
/**
* Test for undesired behaviour observable as of svn revision 618865 (5-Feb-2008).
* POIFSFileSystem was not closing the input stream.
*/
public void testAlwaysClose() {
-
+
TestIS testIS;
-
+
// Normal case - read until EOF and close
testIS = new TestIS(openSampleStream("13224.xls"), -1);
try {
throw new RuntimeException(e);
}
assertTrue("input stream was not closed", testIS.isClosed());
-
+
// intended to crash after reading 10000 bytes
testIS = new TestIS(openSampleStream("13224.xls"), 10000);
try {
// expected
}
assertTrue("input stream was not closed", testIS.isClosed()); // but still should close
-
}
-
+
/**
* Test for bug # 48898 - problem opening an OLE2
* file where the last block is short (i.e. not a full
* multiple of 512 bytes)
- *
+ *
* As yet, this problem remains. One school of thought is
* not not issue an EOF when we discover the last block
* is short, but this seems a bit wrong.
*/
public void testShortLastBlock() throws Exception {
String[] files = new String[] {
- "ShortLastBlock.qwp", "ShortLastBlock.wps"
+ "ShortLastBlock.qwp", "ShortLastBlock.wps"
};
- POIDataSamples _samples = POIDataSamples.getPOIFSInstance();
- for(int i=0; i<files.length; i++) {
+ POIDataSamples _samples = POIDataSamples.getPOIFSInstance();
+ for(int i=0; i<files.length; i++) {
// Open the file up
POIFSFileSystem fs = new POIFSFileSystem(
_samples.openResourceAsStream(files[i])
);
-
+
// Write it into a temp output array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
fs.writeFilesystem(baos);
-
+
// Check sizes
}
}