From: Nick Burch Date: Sat, 29 Mar 2008 17:00:47 +0000 (+0000) Subject: Merged revisions 638001-638784,638786-639486,639488-639601,639603-639836 via svnmerge... X-Git-Tag: REL_3_5_BETA2~164 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fb33f585f596d2d149409e5c88e8f4a7ea47921a;p=poi.git Merged revisions 638001-638784,638786-639486,639488-639601,639603-639836 via svnmerge from https://svn.apache.org/repos/asf/poi/trunk ........ r638803 | nick | 2008-03-19 11:57:38 +0000 (Wed, 19 Mar 2008) | 1 line Added test to show that bug #41546 is already fixed. Also rename a test file to be more consistent ........ r638804 | nick | 2008-03-19 12:01:32 +0000 (Wed, 19 Mar 2008) | 1 line Add test to show that bug #43251 is already fixed ........ r638812 | nick | 2008-03-19 12:28:56 +0000 (Wed, 19 Mar 2008) | 1 line Patch from Dmitriy from bug #30311 - Support for conditional formatting records ........ r638815 | nick | 2008-03-19 12:49:35 +0000 (Wed, 19 Mar 2008) | 1 line Fix bug #44627 - improve the thread safety of POILogFactory ........ r639231 | nick | 2008-03-20 10:06:59 +0000 (Thu, 20 Mar 2008) | 1 line Test relating to bug #44636 ........ r639232 | nick | 2008-03-20 10:16:15 +0000 (Thu, 20 Mar 2008) | 1 line Simple patch from Josh from bug #44636 - fix for RefVPtg and edit-in-excel oddness ........ r639242 | nick | 2008-03-20 11:02:39 +0000 (Thu, 20 Mar 2008) | 1 line Fix for readCompressedUnicode not moaning about length=0, from bug #44643 ........ r639254 | nick | 2008-03-20 11:43:14 +0000 (Thu, 20 Mar 2008) | 1 line Make junit happy ........ r639836 | nick | 2008-03-21 21:04:47 +0000 (Fri, 21 Mar 2008) | 1 line Tweak how you get dataformat strings out of cell styles, to be more logical, and in keeping with how we'll want to do things for xssf too ........ git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@642557 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 4bfd32b0e6..b1504a7023 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -36,6 +36,9 @@ + 44636 - Fix formula parsing of RefVPtg, which was causing #VALUE to be shown on subsequent edits + 44627 - Improve the thread safety of POILogFactory + 30311 - Initial support for Conditional Formatting 44609 - Handle leading spaces in formulas, such as '= 4' 44608 - Support for PercentPtg in the formula evaluator 44606 - Support calculated string values for evaluated formulas diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index a6467d5164..d29d57ff8d 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -33,6 +33,9 @@ + 44636 - Fix formula parsing of RefVPtg, which was causing #VALUE to be shown on subsequent edits + 44627 - Improve the thread safety of POILogFactory + 30311 - Initial support for Conditional Formatting 44609 - Handle leading spaces in formulas, such as '= 4' 44608 - Support for PercentPtg in the formula evaluator 44606 - Support calculated string values for evaluated formulas diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index f3f7deba07..451cde7579 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -24,6 +24,7 @@ import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate; import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate; import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate; import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate; +import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate; import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.util.PaneInformation; @@ -96,6 +97,7 @@ public class Sheet implements Model protected ObjectProtectRecord objprotect = null; protected ScenarioProtectRecord scenprotect = null; protected PasswordRecord password = null; + protected List condFormatting = new ArrayList();; /** Add an UncalcedRecord if not true indicating formulas have not been calculated */ protected boolean uncalced = false; @@ -184,6 +186,17 @@ public class Sheet implements Model retval.merged = ( MergeCellsRecord ) rec; retval.numMergedRegions += retval.merged.getNumAreas(); } + else if ( rec.getSid() == CFHeaderRecord.sid ) + { + CFRecordsAggregate cfAgg = CFRecordsAggregate.createCFAggregate(recs, k); + retval.condFormatting.add(cfAgg); + rec = cfAgg; + } + else if ( rec.getSid() == CFRuleRecord.sid ) + { + // Skip it since it is processed by CFRecordsAggregate + rec = null; + } else if (rec.getSid() == ColumnInfoRecord.sid) { ColumnInfoRecord col = (ColumnInfoRecord)rec; @@ -604,6 +617,66 @@ public class Sheet implements Model { return numMergedRegions; } + // Find correct position to add new CF record + private int findConditionalFormattingPosition() + { + // This is default. + // If the algorithm does not find the right position, + // this one will be used (this is a position before EOF record) + int index = records.size()-2; + + for( int i=index; i>=0; i-- ) + { + Record rec = (Record)records.get(i); + short sid = rec.getSid(); + + // CFRecordsAggregate records already exist, just add to the end + if (rec instanceof CFRecordsAggregate) { return i+1; } + + if( sid == (short)0x00ef ) { return i+1; }// PHONETICPR + if( sid == (short)0x015f ) { return i+1; }// LABELRANGES + if( sid == MergeCellsRecord.sid ) { return i+1; } + if( sid == (short)0x0099 ) { return i+1; }// STANDARDWIDTH + if( sid == SelectionRecord.sid ) { return i+1; } + if( sid == PaneRecord.sid ) { return i+1; } + if( sid == SCLRecord.sid ) { return i+1; } + if( sid == WindowTwoRecord.sid ) { return i+1; } + } + + return index; + } + + public int addConditionalFormatting(CFRecordsAggregate cfAggregate) + { + int index = findConditionalFormattingPosition(); + records.add(index, cfAggregate); + condFormatting.add(cfAggregate); + return condFormatting.size()-1; + } + + public void removeConditionalFormatting(int index) + { + if (index >= 0 && index <= condFormatting.size()-1 ) + { + CFRecordsAggregate cfAggregate = getCFRecordsAggregateAt(index); + records.remove(cfAggregate); + condFormatting.remove(index); + } + } + + public CFRecordsAggregate getCFRecordsAggregateAt(int index) + { + if (index >= 0 && index <= condFormatting.size()-1 ) + { + return (CFRecordsAggregate) condFormatting.get(index); + } + return null; + } + + public int getNumConditionalFormattings() + { + return condFormatting.size(); + } /** * Returns the number of low level binary records in this sheet. This adjusts things for the so called diff --git a/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java b/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java new file mode 100644 index 0000000000..00a8646b4f --- /dev/null +++ b/src/java/org/apache/poi/hssf/record/CFHeaderRecord.java @@ -0,0 +1,223 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +/* + * ConditionalFormattingHeaderRecord.java + * + * Created on January 17, 2008, 3:05 AM + */ +package org.apache.poi.hssf.record; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.poi.hssf.record.cf.CellRange; +import org.apache.poi.util.LittleEndian; + +/** + * Conditional Formatting Header record (CFHEADER) + * + * @author Dmitriy Kumshayev + */ +public class CFHeaderRecord extends Record +{ + public static final short sid = 0x1B0; + + private int field_1_numcf; + private int field_2_need_recalculation; + private CellRange field_3_enclosing_cell_range; + private List field_4_cell_ranges; + + /** Creates new CFHeaderRecord */ + public CFHeaderRecord() + { + field_4_cell_ranges = new ArrayList(5); + } + + public CFHeaderRecord(RecordInputStream in) + { + super(in); + } + + protected void fillFields(RecordInputStream in) + { + field_1_numcf = in.readShort(); + field_2_need_recalculation = in.readShort(); + field_3_enclosing_cell_range = new CellRange(in.readShort(),in.readShort(),in.readShort(),in.readShort()); + int numCellRanges = in.readShort(); + field_4_cell_ranges = new ArrayList(5); + for( int i=0; i0) + { + buffer.append(" .cfranges=["); + for( int i=0; i