poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r700243 [2/2] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/eventmodel/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/aggregates/ sr...
Date Mon, 29 Sep 2008 20:38:56 GMT
Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/StringRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/StringRecord.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/StringRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/StringRecord.java Mon Sep 29 13:38:55
2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,7 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
@@ -23,14 +21,12 @@
 import org.apache.poi.util.StringUtil;
 
 /**
- * Supports the STRING record structure.
+ * Supports the STRING record structure. (0x0207)
  *
  * @author Glen Stampoultzis (glens at apache.org)
  */
-public class StringRecord
-        extends Record
-{
-    public final static short   sid = 0x207;
+public class StringRecord extends Record {
+    public final static short   sid = 0x0207;
     private int                 field_1_string_length;
     private byte                field_2_unicode_flag;
     private String              field_3_string;
@@ -73,7 +69,7 @@
         field_1_string_length           = in.readShort();
         field_2_unicode_flag            = in.readByte();
         byte[] data = in.readRemainder();
-        //Why isnt this using the in.readString methods???
+        //Why isn't this using the in.readString methods???
         if (isUnCompressedUnicode())
         {
             field_3_string = StringUtil.getFromUnicodeLE(data, 0, field_1_string_length );
@@ -92,11 +88,6 @@
     	}
     }
 
-    public boolean isInValueSection()
-    {
-        return true;
-    }
-
     private int getStringByteLength()
     {
         return isUnCompressedUnicode() ? field_1_string_length * 2 : field_1_string_length;
@@ -130,8 +121,8 @@
      */
     public int serialize( int offset, byte[] data )
     {
-        LittleEndian.putShort(data, 0 + offset, sid);
-        LittleEndian.putShort(data, 2 + offset, ( short ) (3 + getStringByteLength()));
+        LittleEndian.putUShort(data, 0 + offset, sid);
+        LittleEndian.putUShort(data, 2 + offset, 3 + getStringByteLength());
         LittleEndian.putUShort(data, 4 + offset, field_1_string_length);
         data[6 + offset] = field_2_unicode_flag;
         if (isUnCompressedUnicode())
@@ -180,8 +171,6 @@
         setCompressedFlag(StringUtil.hasMultibyte(string) ?  (byte)1 : (byte)0);        
     }
 
-
-
     public String toString()
     {
         StringBuffer buffer = new StringBuffer();
@@ -199,7 +188,5 @@
         rec.field_2_unicode_flag= this.field_2_unicode_flag;
         rec.field_3_string = this.field_3_string;
         return rec;
-
     }
-
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
(original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/CFRecordsAggregate.java
Mon Sep 29 13:38:55 2008
@@ -24,7 +24,10 @@
 import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.Record;
-import org.apache.poi.ss.util.Region;
+import org.apache.poi.hssf.record.formula.AreaErrPtg;
+import org.apache.poi.hssf.record.formula.AreaPtg;
+import org.apache.poi.hssf.record.formula.FormulaShifter;
+import org.apache.poi.hssf.record.formula.Ptg;
 import org.apache.poi.ss.util.CellRangeAddress;
 
 /**
@@ -175,4 +178,68 @@
 			rv.visitRecord(rule);
 		}
 	}
+
+	/**
+	 * @return <code>false</code> if this whole {@link CFHeaderRecord} / {@link
CFRuleRecord}s should be deleted
+	 */
+	public boolean updateFormulasAfterCellShift(FormulaShifter shifter, int currentExternSheetIx)
{
+		CellRangeAddress[] cellRanges = header.getCellRanges();
+		boolean changed = false;
+		List temp = new ArrayList();
+		for (int i = 0; i < cellRanges.length; i++) {
+			CellRangeAddress craOld = cellRanges[i];
+			CellRangeAddress craNew = shiftRange(shifter, craOld, currentExternSheetIx);
+			if (craNew == null) {
+				changed = true;
+				continue;
+			}
+			temp.add(craNew);
+			if (craNew != craOld) {
+				changed = true;
+			}
+		}
+
+		if (changed) {
+			int nRanges = temp.size();
+			if (nRanges == 0) {
+				return false;
+			}
+			CellRangeAddress[] newRanges = new CellRangeAddress[nRanges];
+			temp.toArray(newRanges);
+			header.setCellRanges(newRanges);
+		}
+		
+		for(int i=0; i<rules.size(); i++) {
+			CFRuleRecord rule = (CFRuleRecord)rules.get(i);
+			Ptg[] ptgs;
+			ptgs = rule.getParsedExpression1();
+			if (ptgs != null && shifter.adjustFormula(ptgs, currentExternSheetIx)) {
+				rule.setParsedExpression1(ptgs);
+			}
+			ptgs = rule.getParsedExpression2();
+			if (ptgs != null && shifter.adjustFormula(ptgs, currentExternSheetIx)) {
+				rule.setParsedExpression2(ptgs);
+			}
+		}
+		return true;
+	}
+
+	private static CellRangeAddress shiftRange(FormulaShifter shifter, CellRangeAddress cra,
int currentExternSheetIx) {
+		// FormulaShifter works well in terms of Ptgs - so convert CellRangeAddress to AreaPtg
(and back) here
+		AreaPtg aptg = new AreaPtg(cra.getFirstRow(), cra.getLastRow(), cra.getFirstColumn(), cra.getLastColumn(),
false, false, false, false);
+		Ptg[] ptgs = { aptg, };
+		
+		if (!shifter.adjustFormula(ptgs, currentExternSheetIx)) {
+			return cra;
+		}
+		Ptg ptg0 = ptgs[0];
+		if (ptg0 instanceof AreaPtg) {
+			AreaPtg bptg = (AreaPtg) ptg0;
+			return new CellRangeAddress(bptg.getFirstRow(), bptg.getLastRow(), bptg.getFirstColumn(),
bptg.getLastColumn());
+		}
+		if (ptg0 instanceof AreaErrPtg) {
+			return null;
+		}
+		throw new IllegalStateException("Unexpected shifted ptg class (" + ptg0.getClass().getName()
+ ")");
+	}
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java
(original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ConditionalFormattingTable.java
Mon Sep 29 13:38:55 2008
@@ -22,6 +22,7 @@
 
 import org.apache.poi.hssf.model.RecordStream;
 import org.apache.poi.hssf.record.CFHeaderRecord;
+import org.apache.poi.hssf.record.formula.FormulaShifter;
 
 /**
  * Holds all the conditional formatting for a workbook sheet.<p/>
@@ -85,4 +86,15 @@
 					+ " is outside the allowable range (0.." + (_cfHeaders.size() - 1) + ")");
 		}
 	}
+
+	public void updateFormulasAfterCellShift(FormulaShifter shifter, int externSheetIndex) {
+		for (int i = 0; i < _cfHeaders.size(); i++) {
+			CFRecordsAggregate subAgg = (CFRecordsAggregate) _cfHeaders.get(i);
+			boolean shouldKeep = subAgg.updateFormulasAfterCellShift(shifter, externSheetIndex);
+			if (!shouldKeep) {
+				_cfHeaders.remove(i);
+				i--;
+			}
+		}
+	}
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java
(original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/FormulaRecordAggregate.java
Mon Sep 29 13:38:55 2008
@@ -47,12 +47,12 @@
         }
         boolean hasStringRec = stringRec != null;
         boolean hasCachedStringFlag = formulaRec.hasCachedResultString();
-		if (hasStringRec != hasCachedStringFlag) {
-			throw new RecordFormatException("String record was "
-					+ (hasStringRec ? "": "not ") + " supplied but formula record flag is "
-					+ (hasCachedStringFlag ? "" : "not ") + " set");
-		}
-        	
+        if (hasStringRec != hasCachedStringFlag) {
+            throw new RecordFormatException("String record was "
+                    + (hasStringRec ? "": "not ") + " supplied but formula record flag is
"
+                    + (hasCachedStringFlag ? "" : "not ") + " set");
+        }
+
         if (formulaRec.isSharedFormula()) {
             svm.convertSharedFormulaRecord(formulaRec);
         }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java
(original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java
Mon Sep 29 13:38:55 2008
@@ -83,7 +83,7 @@
                 // might need to keep track of where exactly these belong
                 continue;
             }
-            if (!rec.isValue()) {
+            if (!(rec instanceof CellValueRecordInterface)) {
                 throw new RuntimeException("Unexpected record type (" + rec.getClass().getName()
+ ")");
             }
             _valuesAgg.construct((CellValueRecordInterface)rec, rs, svm);

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java Mon Sep 29 13:38:55
2008
@@ -1278,7 +1278,7 @@
         int sheetIndex = workbook.getSheetIndex(this);
         short externSheetIndex = book.checkExternSheet(sheetIndex);
         FormulaShifter shifter = FormulaShifter.createForRowShift(externSheetIndex, startRow,
endRow, n);
-        sheet.getRowsAggregate().updateFormulasAfterRowShift(shifter, externSheetIndex);
+        sheet.updateFormulasAfterCellShift(shifter, externSheetIndex);
 
         int nSheets = workbook.getNumberOfSheets();
         for(int i=0; i<nSheets; i++) {
@@ -1287,7 +1287,7 @@
                 continue;
             }
             short otherExtSheetIx = book.checkExternSheet(i);
-            otherSheet.getRowsAggregate().updateFormulasAfterRowShift(shifter, otherExtSheetIx);
+            otherSheet.updateFormulasAfterCellShift(shifter, otherExtSheetIx);
         }
         // TODO - adjust formulas in named ranges
     }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
(original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheetConditionalFormatting.java
Mon Sep 29 13:38:55 2008
@@ -20,6 +20,7 @@
 import org.apache.poi.hssf.model.Sheet;
 import org.apache.poi.hssf.record.CFRuleRecord;
 import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
+import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
 import org.apache.poi.ss.util.Region;
 import org.apache.poi.ss.util.CellRangeAddress;
 
@@ -31,11 +32,11 @@
 public final class HSSFSheetConditionalFormatting {
 	
 	private final HSSFWorkbook _workbook;
-	private final Sheet _sheet;
+	private final ConditionalFormattingTable _conditionalFormattingTable;
 
 	/* package */ HSSFSheetConditionalFormatting(HSSFWorkbook workbook, Sheet sheet) {
 		_workbook = workbook;
-		_sheet = sheet;
+		_conditionalFormattingTable = sheet.getConditionalFormattingTable();
 	}
 
 	/**
@@ -99,7 +100,7 @@
 	public int addConditionalFormatting( HSSFConditionalFormatting cf ) {
 		CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
 
-		return _sheet.addConditionalFormatting(cfraClone);
+		return _conditionalFormattingTable.add(cfraClone);
 	}
 	/**
 	 * @deprecated use <tt>CellRangeAddress</tt> instead of <tt>Region</tt>
@@ -134,7 +135,7 @@
 			rules[i] = cfRules[i].getCfRuleRecord();
 		}
 		CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
-		return _sheet.addConditionalFormatting(cfra);
+		return _conditionalFormattingTable.add(cfra);
 	}
 
 	public int addConditionalFormatting(CellRangeAddress[] regions,
@@ -166,7 +167,7 @@
 	* @return Conditional Formatting object
 	*/
 	public HSSFConditionalFormatting getConditionalFormattingAt(int index) {
-		CFRecordsAggregate cf = _sheet.getCFRecordsAggregateAt(index);
+		CFRecordsAggregate cf = _conditionalFormattingTable.get(index);
 		if (cf == null) {
 			return null;
 		}
@@ -177,7 +178,7 @@
 	* @return number of Conditional Formatting objects of the sheet
 	*/
 	public int getNumConditionalFormattings() {
-		return _sheet.getNumConditionalFormattings();
+		return _conditionalFormattingTable.size();
 	}
 
 	/**
@@ -185,6 +186,6 @@
 	* @param index of a Conditional Formatting object to remove
 	*/
 	public void removeConditionalFormatting(int index) {
-		_sheet.removeConditionalFormatting(index);
+		_conditionalFormattingTable.remove(index);
 	}
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java Mon Sep 29
13:38:55 2008
@@ -33,6 +33,7 @@
 import org.apache.poi.ddf.EscherBitmapBlip;
 import org.apache.poi.ddf.EscherBlipRecord;
 import org.apache.poi.ddf.EscherRecord;
+import org.apache.poi.hssf.model.RecordStream;
 import org.apache.poi.hssf.model.Sheet;
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.AbstractEscherHolderRecord;
@@ -277,10 +278,9 @@
 
         // convert all LabelRecord records to LabelSSTRecord
         convertLabelRecords(records, recOffset);
-        while (recOffset < records.size()) {
-            Sheet sheet = Sheet.createSheet(records, sheetNum++, recOffset );
-
-            recOffset = sheet.getEofLoc()+1; // TODO - use better technique to keep track
of the used records
+        RecordStream rs = new RecordStream(records, recOffset);
+        while (rs.hasNext()) {
+            Sheet sheet = Sheet.createSheet(rs);
             _sheets.add(new HSSFSheet(this, sheet));
         }
 

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java (original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java Mon Sep 29 13:38:55
2008
@@ -56,6 +56,11 @@
  * @author Glen Stampoultzis (glens at apache.org)
  */
 public final class TestSheet extends TestCase {
+    private static Sheet createSheet(List inRecs) {
+        return Sheet.createSheet(new RecordStream(inRecs, 0));
+    }
+	
+	
     public void testCreateSheet() {
         // Check we're adding row and cell aggregates
         List records = new ArrayList();
@@ -63,7 +68,7 @@
         records.add( new DimensionsRecord() );
         records.add(createWindow2Record());
         records.add(EOFRecord.instance);
-        Sheet sheet = Sheet.createSheet( records, 0, 0 );
+        Sheet sheet = createSheet(records);
 
         int pos = 0;
         assertTrue( sheet.records.get(pos++) instanceof BOFRecord );
@@ -187,7 +192,7 @@
         records.add(EOFRecord.instance);
         records.add(merged);
 
-        Sheet sheet = Sheet.createSheet(records, 0);
+        Sheet sheet = createSheet(records);
         sheet.records.remove(0);
 
         //stub object to throw off list INDEX operations
@@ -222,7 +227,7 @@
         records.add(createWindow2Record());
         records.add(EOFRecord.instance);
 
-        Sheet sheet = Sheet.createSheet(records, 0);
+        Sheet sheet = createSheet(records);
         assertNotNull("Row [2] was skipped", sheet.getRow(2));
     }
 
@@ -446,7 +451,7 @@
         records.add(new DimensionsRecord());
         records.add(createWindow2Record());
         records.add(EOFRecord.instance);
-        Sheet sheet = Sheet.createSheet(records, 0, 0);
+        Sheet sheet = createSheet(records);
         
         // The original bug was due to different logic for collecting records for sizing
and 
         // serialization. The code has since been refactored into a single method for visiting

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/TestExternalNameRecord.java
Mon Sep 29 13:38:55 2008
@@ -82,11 +82,9 @@
 		assertTrue(enr.isAutomaticLink());
 		assertFalse(enr.isBuiltInName());
 		assertFalse(enr.isIconifiedPictureLink());
-		assertFalse(enr.isInValueSection());
 		assertFalse(enr.isOLELink());
 		assertFalse(enr.isPicureLink());
 		assertTrue(enr.isStdDocumentNameIdentifier());
-		assertFalse(enr.isValue());
 
 		TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataAutoDocName, enr.serialize());
 	}
@@ -98,11 +96,9 @@
 		assertFalse(enr.isAutomaticLink());
 		assertFalse(enr.isBuiltInName());
 		assertFalse(enr.isIconifiedPictureLink());
-		assertFalse(enr.isInValueSection());
 		assertFalse(enr.isOLELink());
 		assertFalse(enr.isPicureLink());
 		assertFalse(enr.isStdDocumentNameIdentifier());
-		assertFalse(enr.isValue());
 
 		TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataPlainName, enr.serialize());
 	}

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
Mon Sep 29 13:38:55 2008
@@ -65,7 +65,7 @@
     }
 
     private void constructValueRecord(List records) {
-        RowBlocksReader rbr = new RowBlocksReader(records, 0);
+        RowBlocksReader rbr = new RowBlocksReader(new RecordStream(records, 0));
         SharedValueManager sfrh = rbr.getSharedFormulaManager();
         RecordStream rs = rbr.getPlainRecordStream();
         while(rs.hasNext()) {

Modified: poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java?rev=700243&r1=700242&r2=700243&view=diff
==============================================================================
--- poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
(original)
+++ poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFConditionalFormatting.java
Mon Sep 29 13:38:55 2008
@@ -29,10 +29,8 @@
  * 
  * @author Dmitriy Kumshayev
  */
-public final class TestHSSFConditionalFormatting extends TestCase
-{
-	public void testCreateCF() 
-	{
+public final class TestHSSFConditionalFormatting extends TestCase {
+	public void testCreateCF() {
 		HSSFWorkbook workbook = new HSSFWorkbook();
 		HSSFSheet sheet = workbook.createSheet();
 		String formula = "7";
@@ -150,4 +148,44 @@
 		}
 		assertEquals(2, wb.getNumberOfSheets());
 	}
+
+	public void testShiftRows() {
+
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet sheet = wb.createSheet();
+
+		HSSFSheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
+
+		HSSFConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(
+				ComparisonOperator.BETWEEN, "sum(A10:A15)", "1+sum(B16:B30)");
+		HSSFFontFormatting fontFmt = rule1.createFontFormatting();
+		fontFmt.setFontStyle(true, false);
+
+		HSSFPatternFormatting patternFmt = rule1.createPatternFormatting();
+		patternFmt.setFillBackgroundColor(HSSFColor.YELLOW.index);
+		HSSFConditionalFormattingRule [] cfRules = { rule1, };
+
+		CellRangeAddress [] regions = {
+			new CellRangeAddress(2, 4, 0, 0), // A3:A5
+		};
+		sheetCF.addConditionalFormatting(regions, cfRules);
+
+		// This row-shift should destroy the CF region
+		sheet.shiftRows(10, 20, -9);
+		assertEquals(0, sheetCF.getNumConditionalFormattings());
+
+		// re-add the CF
+		sheetCF.addConditionalFormatting(regions, cfRules);
+
+		// This row shift should only affect the formulas
+		sheet.shiftRows(14, 17, 8);
+		HSSFConditionalFormatting cf = sheetCF.getConditionalFormattingAt(0);
+		assertEquals("SUM(A10:A23)", cf.getRule(0).getFormula1());
+		assertEquals("1+SUM(B24:B30)", cf.getRule(0).getFormula2());
+
+		sheet.shiftRows(0, 8, 21);
+		cf = sheetCF.getConditionalFormattingAt(0);
+		assertEquals("SUM(A10:A21)", cf.getRule(0).getFormula1());
+		assertEquals("1+SUM(#REF!)", cf.getRule(0).getFormula2());
+	}
 }



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


Mime
View raw message