poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r832584 - in /poi/trunk: src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/eventusermodel/ src/java/org/apache/poi/hssf/record/ src/testcases/org/apache/poi/hssf/eventusermodel/ test-data/spreadsheet/
Date Tue, 03 Nov 2009 22:45:56 GMT
Author: nick
Date: Tue Nov  3 22:45:39 2009
New Revision: 832584

URL: http://svn.apache.org/viewvc?rev=832584&view=rev
Log:
Hopefully fix #45672 properly - improve handling by MissingRecordAwareHSSFListener of records
that cover multiple cells (MulBlankRecord and MulRKRecord)

Added:
    poi/trunk/test-data/spreadsheet/45672.xls   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java
    poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java
    poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java
    poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=832584&r1=832583&r2=832584&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Tue Nov  3 22:45:39 2009
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.6-beta1" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45672 - improve handling by MissingRecordAwareHSSFListener
of records that cover multiple cells (MulBlankRecord and MulRKRecord)</action>
            <action dev="POI-DEVELOPERS" type="fix">48096 - relaxed validation check
in RecalcIdRecord</action>
            <action dev="POI-DEVELOPERS" type="fix">48085 - improved error checking
in BlockAllocationTableReader to trap unreasonable field values</action>
            <action dev="POI-DEVELOPERS" type="fix">47924 - fixed logic for matching
cells and comments in HSSFCell.getCellComment()</action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java?rev=832584&r1=832583&r2=832584&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java
(original)
+++ poi/trunk/src/java/org/apache/poi/hssf/eventusermodel/MissingRecordAwareHSSFListener.java
Tue Nov  3 22:45:39 2009
@@ -21,9 +21,14 @@
 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;
 import org.apache.poi.hssf.record.SharedFormulaRecord;
 
@@ -62,7 +67,7 @@
 	public void processRecord(Record record) {
 		int thisRow;
 		int thisColumn;
-
+		CellValueRecordInterface[] expandedRecords = null;
 
 		if (record instanceof CellValueRecordInterface) {
 			CellValueRecordInterface valueRec = (CellValueRecordInterface) record;
@@ -105,6 +110,19 @@
 					// - so don't fire off the LastCellOfRowDummyRecord yet
 					childListener.processRecord(record);
 					return;
+				case MulBlankRecord.sid:
+					// These appear in the middle of the cell records, to
+					//  specify that the next bunch are empty but styled
+					// Expand this out into multiple blank cells
+					MulBlankRecord mbr = (MulBlankRecord)record;
+					expandedRecords = RecordFactory.convertBlankRecords(mbr);
+					break;
+				case MulRKRecord.sid:
+					// This is multiple consecutive number cells in one record
+					// Exand this out into multiple regular number cells
+					MulRKRecord mrk = (MulRKRecord)record;
+					expandedRecords = RecordFactory.convertRKRecords(mrk);
+					break;
 				case NoteRecord.sid:
 					NoteRecord nrec = (NoteRecord) record;
 					thisRow = nrec.getRow();
@@ -112,6 +130,13 @@
 					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 
 		//  dummy end-of-row records
@@ -148,13 +173,26 @@
 			}
 		}
 		
+		// 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;
 			lastCellRow = thisRow;
 		}
 
-		childListener.processRecord(record);
+		// Pass along the record(s)
+		if(expandedRecords != null && expandedRecords.length > 0) {
+			for(CellValueRecordInterface r : expandedRecords) {
+				childListener.processRecord((Record)r);
+			}
+		} else {
+			childListener.processRecord(record);
+		}
 	}
 
 	private void resetCounts() {

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java?rev=832584&r1=832583&r2=832584&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/MulBlankRecord.java Tue Nov  3 22:45:39
2009
@@ -56,6 +56,13 @@
 	public int getFirstColumn() {
 		return _firstCol;
 	}
+	
+	/**
+	 * @return ending column (last cell this holds in the row). Zero based
+	 */
+	public int getLastColumn() {
+		return _lastCol;
+	}
 
 	/**
 	 * get the number of columns this contains (last-first +1)

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java?rev=832584&r1=832583&r2=832584&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/RecordFactory.java Tue Nov  3 22:45:39 2009
@@ -281,7 +281,6 @@
 	 * Converts a {@link MulRKRecord} into an equivalent array of {@link NumberRecord}s
 	 */
 	public static NumberRecord[] convertRKRecords(MulRKRecord mrk) {
-
 		NumberRecord[] mulRecs = new NumberRecord[mrk.getNumColumns()];
 		for (int k = 0; k < mrk.getNumColumns(); k++) {
 			NumberRecord nr = new NumberRecord();
@@ -296,6 +295,22 @@
 	}
 
 	/**
+	 * Converts a {@link MulBlankRecord} into an equivalent array of {@link BlankRecord}s
+	 */
+	public static BlankRecord[] convertBlankRecords(MulBlankRecord mbk) {
+		BlankRecord[] mulRecs = new BlankRecord[mbk.getNumColumns()];
+		for (int k = 0; k < mbk.getNumColumns(); k++) {
+			BlankRecord br = new BlankRecord();
+
+			br.setColumn((short) (k + mbk.getFirstColumn()));
+			br.setRow(mbk.getRow());
+			br.setXFIndex(mbk.getXFAt(k));
+			mulRecs[k] = br;
+		}
+		return mulRecs;
+	}
+
+	/**
 	 * @return an array of all the SIDS for all known records
 	 */
 	public static short[] getAllKnownRecordSIDs() {

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java?rev=832584&r1=832583&r2=832584&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
(original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/eventusermodel/TestMissingRecordAwareHSSFListener.java
Tue Nov  3 22:45:39 2009
@@ -29,7 +29,9 @@
 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.LabelSSTRecord;
+import org.apache.poi.hssf.record.MulBlankRecord;
 import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.record.RowRecord;
 import org.apache.poi.hssf.record.SharedFormulaRecord;
@@ -422,4 +424,41 @@
 		assertEquals(1, eorCount);
 		assertEquals(1, sfrCount);
 	}
+	
+	/**
+	 * MulBlank records hold multiple blank cells. Check we
+	 *  can handle them correctly.
+	 */
+	public void testMulBlankHandling() {
+		readRecords("45672.xls");
+		
+		// Check that we don't have any MulBlankRecords, but do
+		//  have lots of BlankRecords
+		Record[] rr = r;
+		int eorCount=0;
+		int mbrCount=0;
+		int brCount=0;
+		for (int i = 0; i < rr.length; i++) {
+			Record record = rr[i];
+			if (record instanceof MulBlankRecord) {
+				mbrCount++;
+			}
+			if (record instanceof BlankRecord) {
+				brCount++;
+			}
+			if (record instanceof LastCellOfRowDummyRecord) {
+				eorCount++;
+			}
+		}
+		if (mbrCount > 0) {
+			throw new AssertionFailedError("Identified bug 45672");
+		}
+		if (brCount < 20) {
+			throw new AssertionFailedError("Identified bug 45672");
+		}
+		if (eorCount != 2) {
+			throw new AssertionFailedError("Identified bug 45672");
+		}
+		assertEquals(2, eorCount);
+	}
 }

Added: poi/trunk/test-data/spreadsheet/45672.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/45672.xls?rev=832584&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/45672.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message