ComparisonOperator.NO_COMPARISON);
DataBarFormatting dbf = r.createDataBarFormatting();
dbf.setColor(color);
- dbf.setPercentMin((byte)50);
- dbf.setPercentMax((byte)50);
+ dbf.setPercentMin((byte)0);
+ dbf.setPercentMax((byte)100);
DataBarThreshold min = new DataBarThreshold();
min.setType(RangeType.MIN.id);
import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.cf.BorderFormatting;
import org.apache.poi.hssf.record.cf.ColorGradientFormatting;
+import org.apache.poi.hssf.record.cf.DataBarFormatting;
import org.apache.poi.hssf.record.cf.FontFormatting;
import org.apache.poi.hssf.record.cf.IconMultiStateFormatting;
import org.apache.poi.hssf.record.cf.PatternFormatting;
return (CFRule12Record)cfRuleRecord;
}
- private HSSFFontFormatting getFontFormatting(boolean create)
- {
+ private HSSFFontFormatting getFontFormatting(boolean create) {
FontFormatting fontFormatting = cfRuleRecord.getFontFormatting();
if ( fontFormatting != null)
{
/**
* @return - font formatting object if defined, <code>null</code> otherwise
*/
- public HSSFFontFormatting getFontFormatting()
- {
+ public HSSFFontFormatting getFontFormatting() {
return getFontFormatting(false);
}
/**
* otherwise just return existing object.
* @return - font formatting object, never returns <code>null</code>.
*/
- public HSSFFontFormatting createFontFormatting()
- {
+ public HSSFFontFormatting createFontFormatting() {
return getFontFormatting(true);
}
- private HSSFBorderFormatting getBorderFormatting(boolean create)
- {
+ private HSSFBorderFormatting getBorderFormatting(boolean create) {
BorderFormatting borderFormatting = cfRuleRecord.getBorderFormatting();
if ( borderFormatting != null)
{
/**
* @return - border formatting object if defined, <code>null</code> otherwise
*/
- public HSSFBorderFormatting getBorderFormatting()
- {
+ public HSSFBorderFormatting getBorderFormatting() {
return getBorderFormatting(false);
}
/**
* otherwise just return existing object.
* @return - border formatting object, never returns <code>null</code>.
*/
- public HSSFBorderFormatting createBorderFormatting()
- {
+ public HSSFBorderFormatting createBorderFormatting() {
return getBorderFormatting(true);
}
return getPatternFormatting(true);
}
+ private HSSFDataBarFormatting getDataBarFormatting(boolean create) {
+ CFRule12Record cfRule12Record = getCFRule12Record(create);
+ DataBarFormatting databarFormatting = cfRule12Record.getDataBarFormatting();
+ if (databarFormatting != null)
+ {
+ return new HSSFDataBarFormatting(cfRule12Record, sheet);
+ }
+ else if( create )
+ {
+ databarFormatting = cfRule12Record.createDataBarFormatting();
+ return new HSSFDataBarFormatting(cfRule12Record, sheet);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ /**
+ * @return databar / data-bar formatting object if defined, <code>null</code> otherwise
+ */
+ public HSSFDataBarFormatting getDataBarFormatting() {
+ return getDataBarFormatting(false);
+ }
+ /**
+ * create a new databar / data-bar formatting object if it does not exist,
+ * otherwise just return the existing object.
+ */
+ public HSSFDataBarFormatting createDataBarFormatting() {
+ return getDataBarFormatting(true);
+ }
+
private HSSFIconMultiStateFormatting getMultiStateFormatting(boolean create) {
CFRule12Record cfRule12Record = getCFRule12Record(create);
IconMultiStateFormatting iconFormatting = cfRule12Record.getMultiStateFormatting();
--- /dev/null
+/* ====================================================================
+ 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.
+==================================================================== */
+
+package org.apache.poi.hssf.usermodel;
+
+import org.apache.poi.hssf.record.CFRule12Record;
+import org.apache.poi.hssf.record.cf.DataBarFormatting;
+import org.apache.poi.hssf.record.cf.DataBarThreshold;
+import org.apache.poi.ss.usermodel.Color;
+
+/**
+ * High level representation for DataBar / Data-Bar Formatting
+ * component of Conditional Formatting settings
+ */
+public final class HSSFDataBarFormatting implements org.apache.poi.ss.usermodel.DataBarFormatting {
+ private final HSSFSheet sheet;
+ private final CFRule12Record cfRule12Record;
+ private final DataBarFormatting databarFormatting;
+
+ protected HSSFDataBarFormatting(CFRule12Record cfRule12Record, HSSFSheet sheet) {
+ this.sheet = sheet;
+ this.cfRule12Record = cfRule12Record;
+ this.databarFormatting = this.cfRule12Record.getDataBarFormatting();
+ }
+
+ public boolean isLeftToRight() {
+ return !databarFormatting.isReversed();
+ }
+ public void setLeftToRight(boolean ltr) {
+ databarFormatting.setReversed(!ltr);
+ }
+
+ public int getWidthMin() {
+ return databarFormatting.getPercentMin();
+ }
+ public void setWidthMin(int width) {
+ databarFormatting.setPercentMin((byte)width);
+ }
+
+ public int getWidthMax() {
+ return databarFormatting.getPercentMax();
+ }
+ public void setWidthMax(int width) {
+ databarFormatting.setPercentMax((byte)width);
+ }
+
+ public HSSFExtendedColor getColor() {
+ return new HSSFExtendedColor(databarFormatting.getColor());
+ }
+ public void setColor(Color color) {
+ HSSFExtendedColor hcolor = (HSSFExtendedColor)color;
+ databarFormatting.setColor(hcolor.getExtendedColor());
+ }
+
+ public HSSFConditionalFormattingThreshold getMinThreshold() {
+ return new HSSFConditionalFormattingThreshold(databarFormatting.getThresholdMin(), sheet);
+ }
+ public HSSFConditionalFormattingThreshold getMaxThreshold() {
+ return new HSSFConditionalFormattingThreshold(databarFormatting.getThresholdMax(), sheet);
+ }
+
+ public boolean isIconOnly() {
+ return databarFormatting.isIconOnly();
+ }
+ public void setIconOnly(boolean only) {
+ databarFormatting.setIconOnly(only);
+ }
+
+ public HSSFConditionalFormattingThreshold createThreshold() {
+ return new HSSFConditionalFormattingThreshold(new DataBarThreshold(), sheet);
+ }
+}
*/\r
PatternFormatting getPatternFormatting();\r
\r
+ /**\r
+ * @return - databar / data-bar formatting object if defined, <code>null</code> otherwise\r
+ */\r
+ DataBarFormatting getDataBarFormatting();\r
+ \r
/**\r
* @return - icon / multi-state formatting object if defined, <code>null</code> otherwise\r
*/\r
return new XSSFPatternFormatting(dxf.getFill());\r
}\r
\r
+ public XSSFDataBarFormatting createDataBarFormatting(XSSFColor color) {\r
+ // Is it already there?\r
+ if (_cfRule.isSetDataBar() && _cfRule.getType() == STCfType.DATA_BAR)\r
+ return getDataBarFormatting();\r
+ \r
+ // Mark it as being a Data Bar\r
+ _cfRule.setType(STCfType.DATA_BAR);\r
+\r
+ // Ensure the right element\r
+ CTDataBar bar = null;\r
+ if (_cfRule.isSetDataBar()) {\r
+ bar = _cfRule.getDataBar();\r
+ } else {\r
+ bar = _cfRule.addNewDataBar();\r
+ }\r
+ // Set the color\r
+ bar.setColor(color.getCTColor());\r
+ \r
+ // Add the default thresholds\r
+ CTCfvo min = bar.addNewCfvo();\r
+ min.setType(STCfvoType.Enum.forString(RangeType.MIN.name));\r
+ CTCfvo max = bar.addNewCfvo();\r
+ max.setType(STCfvoType.Enum.forString(RangeType.MAX.name));\r
+ \r
+ // Wrap and return\r
+ return new XSSFDataBarFormatting(bar);\r
+ }\r
+ public XSSFDataBarFormatting getDataBarFormatting() {\r
+ if (_cfRule.isSetDataBar()) {\r
+ CTDataBar bar = _cfRule.getDataBar();\r
+ return new XSSFDataBarFormatting(bar);\r
+ } else {\r
+ return null;\r
+ }\r
+ }\r
+ \r
public XSSFIconMultiStateFormatting createMultiStateFormatting(IconSet iconSet) {\r
// Is it already there?\r
if (_cfRule.isSetIconSet() && _cfRule.getType() == STCfType.ICON_SET)\r
--- /dev/null
+/*\r
+ * ====================================================================\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ====================================================================\r
+ */\r
+package org.apache.poi.xssf.usermodel;\r
+\r
+import org.apache.poi.ss.usermodel.Color;\r
+import org.apache.poi.ss.usermodel.DataBarFormatting;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataBar;\r
+\r
+/**\r
+ * High level representation for DataBar / Data Bar Formatting \r
+ * component of Conditional Formatting settings\r
+ */\r
+public class XSSFDataBarFormatting implements DataBarFormatting {\r
+ CTDataBar _databar;\r
+\r
+ /*package*/ XSSFDataBarFormatting(CTDataBar databar){\r
+ _databar = databar;\r
+ }\r
+\r
+ public boolean isIconOnly() {\r
+ if (_databar.isSetShowValue())\r
+ return !_databar.getShowValue();\r
+ return false;\r
+ }\r
+ public void setIconOnly(boolean only) {\r
+ _databar.setShowValue(!only);\r
+ }\r
+\r
+ public boolean isLeftToRight() {\r
+ return true;\r
+ }\r
+ public void setLeftToRight(boolean ltr) {\r
+ // TODO How does XSSF encode this?\r
+ }\r
+\r
+ public int getWidthMin() {\r
+ return 0;\r
+ }\r
+ public void setWidthMin(int width) {\r
+ // TODO How does XSSF encode this?\r
+ }\r
+\r
+ public int getWidthMax() {\r
+ return 100;\r
+ }\r
+ public void setWidthMax(int width) {\r
+ // TODO How does XSSF encode this?\r
+ }\r
+\r
+ public XSSFColor getColor() {\r
+ return new XSSFColor(_databar.getColor());\r
+ }\r
+ public void setColor(Color color) {\r
+ _databar.setColor( ((XSSFColor)color).getCTColor() );\r
+ }\r
+\r
+ public XSSFConditionalFormattingThreshold getMinThreshold() {\r
+ return new XSSFConditionalFormattingThreshold(_databar.getCfvoArray(0));\r
+ }\r
+ public XSSFConditionalFormattingThreshold getMaxThreshold() {\r
+ return new XSSFConditionalFormattingThreshold(_databar.getCfvoArray(1));\r
+ }\r
+\r
+ public XSSFConditionalFormattingThreshold createThreshold() {\r
+ return new XSSFConditionalFormattingThreshold(_databar.addNewCfvo());\r
+ }\r
+}\r
* {@link XSSFDataBarFormatting#getMaxThreshold()}\r
*/\r
public XSSFConditionalFormattingRule createConditionalFormattingRule(XSSFColor color) {\r
- throw new IllegalStateException("Not Implemented Yet!"); // TODO Implement\r
+ XSSFConditionalFormattingRule rule = new XSSFConditionalFormattingRule(_sheet);\r
+ \r
+ // Have it setup, with suitable defaults\r
+ rule.createDataBarFormatting(color);\r
+ \r
+ // All done!\r
+ return rule;\r
}\r
public XSSFConditionalFormattingRule createConditionalFormattingRule(ExtendedColor color) {\r
return createConditionalFormattingRule((XSSFColor)color);\r
cf = sheetCF.getConditionalFormattingAt(2);\r
assertEquals(1, cf.getFormattingRanges().length);\r
assertEquals("E2:E17", cf.getFormattingRanges()[0].formatAsString());\r
- \r
- assertEquals(1, cf.getNumberOfRules());\r
- cr = cf.getRule(0);\r
- assertEquals(ConditionType.DATA_BAR, cr.getConditionTypeType());\r
- // TODO Support Data Bars, then check the rest of this rule\r
+ assertDataBar(cf, "FF63C384");\r
\r
\r
// Colours Red->Yellow->Green - Column F\r
// TODO Support EXT formattings\r
}\r
\r
+ private void assertDataBar(ConditionalFormatting cf, String color) {\r
+ assertEquals(1, cf.getNumberOfRules());\r
+ ConditionalFormattingRule cr = cf.getRule(0);\r
+ assertDataBar(cr, color);\r
+ }\r
+ private void assertDataBar(ConditionalFormattingRule cr, String color) {\r
+ assertEquals(ConditionType.DATA_BAR, cr.getConditionTypeType());\r
+ assertEquals(ComparisonOperator.NO_COMPARISON, cr.getComparisonOperation());\r
+ assertEquals(null, cr.getFormula1());\r
+ assertEquals(null, cr.getFormula2());\r
+ \r
+ DataBarFormatting databar = cr.getDataBarFormatting();\r
+ assertNotNull(databar);\r
+ assertEquals(false, databar.isIconOnly());\r
+ assertEquals(true, databar.isLeftToRight());\r
+ assertEquals(0, databar.getWidthMin());\r
+ assertEquals(100, databar.getWidthMax());\r
+ \r
+ assertColour(color, databar.getColor());\r
+ \r
+ ConditionalFormattingThreshold th;\r
+ th = databar.getMinThreshold();\r
+ assertEquals(RangeType.MIN, th.getRangeType());\r
+ assertEquals(null, th.getValue());\r
+ assertEquals(null, th.getFormula());\r
+ th = databar.getMaxThreshold();\r
+ assertEquals(RangeType.MAX, th.getRangeType());\r
+ assertEquals(null, th.getValue());\r
+ assertEquals(null, th.getFormula());\r
+ }\r
+ \r
private void assertIconSetPercentages(ConditionalFormatting cf, IconSet iconset, Double...vals) {\r
assertEquals(1, cf.getNumberOfRules());\r
ConditionalFormattingRule cr = cf.getRule(0);\r