From 79879fb28620e4fbde8741ec35dd800c60555e90 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Mon, 5 Oct 2015 00:26:19 +0000 Subject: [PATCH] Fixed a problem with save-and-load of conditional formattings (CFHeader12 wasn't added to conditional formattings, rgb value wasn't saved in extended color) git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1706739 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hssf/model/InternalSheet.java | 3 ++- .../org/apache/poi/hssf/record/CFHeaderBase.java | 16 +++++++++++----- .../poi/hssf/usermodel/HSSFExtendedColor.java | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/java/org/apache/poi/hssf/model/InternalSheet.java b/src/java/org/apache/poi/hssf/model/InternalSheet.java index cbb921b2f7..8cb482a574 100644 --- a/src/java/org/apache/poi/hssf/model/InternalSheet.java +++ b/src/java/org/apache/poi/hssf/model/InternalSheet.java @@ -22,6 +22,7 @@ import java.util.Iterator; import java.util.List; import org.apache.poi.hssf.record.BOFRecord; +import org.apache.poi.hssf.record.CFHeader12Record; import org.apache.poi.hssf.record.CFHeaderRecord; import org.apache.poi.hssf.record.CalcCountRecord; import org.apache.poi.hssf.record.CalcModeRecord; @@ -190,7 +191,7 @@ public final class InternalSheet { while (rs.hasNext()) { int recSid = rs.peekNextSid(); - if ( recSid == CFHeaderRecord.sid ) { + if ( recSid == CFHeaderRecord.sid || recSid == CFHeader12Record.sid ) { condFormatting = new ConditionalFormattingTable(rs); records.add(condFormatting); continue; diff --git a/src/java/org/apache/poi/hssf/record/CFHeaderBase.java b/src/java/org/apache/poi/hssf/record/CFHeaderBase.java index aa9f2daf03..dc7052de45 100644 --- a/src/java/org/apache/poi/hssf/record/CFHeaderBase.java +++ b/src/java/org/apache/poi/hssf/record/CFHeaderBase.java @@ -62,13 +62,17 @@ public abstract class CFHeaderBase extends StandardRecord implements Cloneable { public boolean getNeedRecalculation() { // Held on the 1st bit - return field_2_need_recalculation_and_id % 2 == 1; + return (field_2_need_recalculation_and_id & 1) == 1; } public void setNeedRecalculation(boolean b) { // held on the first bit - if (b == getNeedRecalculation()) return; - if (b) field_2_need_recalculation_and_id++; - else field_2_need_recalculation_and_id--; + if (b == getNeedRecalculation()) { + return; + } else if (b) { + field_2_need_recalculation_and_id++; + } else { + field_2_need_recalculation_and_id--; + } } public int getID() { @@ -79,7 +83,9 @@ public abstract class CFHeaderBase extends StandardRecord implements Cloneable { // Remaining 15 bits of field 2 boolean needsRecalc = getNeedRecalculation(); field_2_need_recalculation_and_id = (id<<1); - if (needsRecalc) field_2_need_recalculation_and_id++; + if (needsRecalc) { + field_2_need_recalculation_and_id++; + } } public CellRangeAddress getEnclosingCellRange() { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFExtendedColor.java b/src/java/org/apache/poi/hssf/usermodel/HSSFExtendedColor.java index 7806fb5184..e6c8c1bf5e 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFExtendedColor.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFExtendedColor.java @@ -97,6 +97,7 @@ public class HSSFExtendedColor extends ExtendedColor { rgb[3] = a; color.setRGBA(rgb); } + color.setType(TYPE_RGB); } public double getTint() {