30311 - More work on Conditional Formatting - patch from Dmitriy

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@645352 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-04-07 03:23:04 +00:00
parent bf756d9678
commit 0a4b7bec9f
10 changed files with 328 additions and 281 deletions

View File

@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.0.3-beta1" date="2008-04-??">
<action dev="POI-DEVELOPERS" type="add">30311 - More work on Conditional Formatting</action>
<action dev="POI-DEVELOPERS" type="fix">refactored all junits' usage of HSSF.testdata.path to one place</action>
<action dev="POI-DEVELOPERS" type="fix">44739 - Small fixes for conditional formatting (regions with max row/col index)</action>
<action dev="POI-DEVELOPERS" type="add">Implement Sheet.removeShape(Shape shape) in HSLF</action>

View File

@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.0.3-beta1" date="2008-04-??">
<action dev="POI-DEVELOPERS" type="add">30311 - More work on Conditional Formatting</action>
<action dev="POI-DEVELOPERS" type="fix">refactored all junits' usage of HSSF.testdata.path to one place</action>
<action dev="POI-DEVELOPERS" type="fix">44739 - Small fixes for conditional formatting (regions with max row/col index)</action>
<action dev="RK" type="add">44694 - HPSF: Support for property sets without sections</action>

View File

@ -238,6 +238,17 @@ public final class CFRuleRecord extends Record
this.fontFormatting = fontFormatting;
setOptionFlag(fontFormatting != null, font);
}
public FontFormatting getFontFormatting()
{
if( containsFontFormattingBlock())
{
return fontFormatting;
}
else
{
return null;
}
}
public boolean containsAlignFormattingBlock()
{
@ -257,6 +268,17 @@ public final class CFRuleRecord extends Record
this.borderFormatting = borderFormatting;
setOptionFlag(borderFormatting != null, bord);
}
public BorderFormatting getBorderFormatting()
{
if( containsBorderFormattingBlock())
{
return borderFormatting;
}
else
{
return null;
}
}
public boolean containsPatternFormattingBlock()
{
@ -267,7 +289,17 @@ public final class CFRuleRecord extends Record
this.patternFormatting = patternFormatting;
setOptionFlag(patternFormatting!=null, patt);
}
public PatternFormatting getPatternFormatting()
{
if( containsPatternFormattingBlock())
{
return patternFormatting;
}
else
{
return null;
}
}
public boolean containsProtectionFormattingBlock()
{
@ -616,12 +648,6 @@ public final class CFRuleRecord extends Record
return rec;
}
public FontFormatting getFontFormatting()
{
return fontFormatting;
}
/**
* @return <code>null</code> if <tt>formula</tt> was null.
*/

View File

@ -45,8 +45,8 @@ public class FontFormatting
private static final int OFFSET_OPTION_FLAGS = 88;
private static final int OFFSET_ESCAPEMENT_TYPE_MODIFIED = 92;
private static final int OFFSET_UNDERLINE_TYPE_MODIFIED = 96;
private static final int OFFSET_NOT_USED1 = 100;
private static final int OFFSET_NOT_USED2 = 104;
private static final int OFFSET_FONT_WEIGHT_MODIFIED = 100;
private static final int OFFSET_NOT_USED = 104;
private static final int OFFSET_FONT_FORMATING_END = 116;
@ -56,7 +56,6 @@ public class FontFormatting
private static final BitField posture = BitFieldFactory.getInstance(0x00000002);
private static final BitField outline = BitFieldFactory.getInstance(0x00000008);
private static final BitField shadow = BitFieldFactory.getInstance(0x00000010);
private static final BitField condense = BitFieldFactory.getInstance(0x00000020);
private static final BitField cancellation = BitFieldFactory.getInstance(0x00000080);
// OPTION FLAGS MASKS
@ -64,7 +63,6 @@ public class FontFormatting
private static final BitField styleModified = BitFieldFactory.getInstance(0x00000002);
private static final BitField outlineModified = BitFieldFactory.getInstance(0x00000008);
private static final BitField shadowModified = BitFieldFactory.getInstance(0x00000010);
private static final BitField condenseModified = BitFieldFactory.getInstance(0x00000020);
private static final BitField cancellationModified = BitFieldFactory.getInstance(0x00000080);
/**
@ -125,10 +123,9 @@ public class FontFormatting
this.setFontHeight((short)-1);
this.setItalic(false);
this.setBold(false);
this.setFontWieghtModified(false);
this.setOutline(false);
this.setShadow(false);
this.setCondense(false);
this.setStrikeout(false);
this.setEscapementType((short)0);
this.setUnderlineType((byte)0);
@ -137,15 +134,13 @@ public class FontFormatting
this.setFontStyleModified(false);
this.setFontOutlineModified(false);
this.setFontShadowModified(false);
this.setFontCondenseModified(false);
this.setFontCancellationModified(false);
this.setEscapementTypeModified(false);
this.setUnderlineTypeModified(false);
LittleEndian.putShort(record, OFFSET_FONT_NAME, (short)0);
LittleEndian.putInt(record, OFFSET_NOT_USED1, 0x00000001);
LittleEndian.putInt(record, OFFSET_NOT_USED2, 0x00000001);
LittleEndian.putInt(record, OFFSET_NOT_USED, 0x00000001);
LittleEndian.putShort(record, OFFSET_FONT_FORMATING_END, (short)0x0001);
}
@ -249,16 +244,6 @@ public class FontFormatting
return getFontOption(shadow);
}
public void setCondense(boolean on)
{
setFontOption(on, condense);
}
public boolean isCondenseOn()
{
return getFontOption(condense);
}
/**
* set the font to be stricken out or not
*
@ -420,6 +405,7 @@ public class FontFormatting
return getOptionFlag(styleModified);
}
public void setFontStyleModified(boolean modified)
{
setOptionFlag(modified, styleModified);
@ -444,16 +430,6 @@ public class FontFormatting
{
setOptionFlag(modified, shadowModified);
}
public boolean isFontCondenseModified()
{
return getOptionFlag(condenseModified);
}
public void setFontCondenseModified(boolean modified)
{
setOptionFlag(modified, condenseModified);
}
public void setFontCancellationModified(boolean modified)
{
setOptionFlag(modified, cancellationModified);
@ -469,7 +445,6 @@ public class FontFormatting
int value = modified? 0 : 1;
LittleEndian.putInt(record,OFFSET_ESCAPEMENT_TYPE_MODIFIED, value);
}
public boolean isEscapementTypeModified()
{
int escapementModified = LittleEndian.getInt(record,OFFSET_ESCAPEMENT_TYPE_MODIFIED);
@ -488,6 +463,18 @@ public class FontFormatting
return underlineModified == 0;
}
public void setFontWieghtModified(boolean modified)
{
int value = modified? 0 : 1;
LittleEndian.putInt(record,OFFSET_FONT_WEIGHT_MODIFIED, value);
}
public boolean isFontWeightModified()
{
int fontStyleModified = LittleEndian.getInt(record,OFFSET_FONT_WEIGHT_MODIFIED);
return fontStyleModified == 0;
}
public String toString()
{
StringBuffer buffer = new StringBuffer();
@ -521,14 +508,6 @@ public class FontFormatting
{
buffer.append(" .font shadow is not modified\n");
}
if( isFontCondenseModified() )
{
buffer.append(" .font condense = ").append(isCondenseOn()).append("\n");
}
else
{
buffer.append(" .font condense is not modified\n");
}
if( isFontCancellationModified() )
{
@ -572,11 +551,32 @@ public class FontFormatting
}
buffer.append(" .color index = ").append("0x"+Integer.toHexString(getFontColorIndex()).toUpperCase()).append("\n");
buffer.append(" ====\n");
buffer.append(" ["+OFFSET_FONT_HEIGHT+"] FONT HEIGHT: "+intToHex(OFFSET_FONT_HEIGHT)+"\n");
buffer.append(" ["+OFFSET_FONT_OPTIONS+"] FONT OPTIONS: "+intToHex(OFFSET_FONT_OPTIONS)+"\n");
buffer.append(" ["+OFFSET_FONT_WEIGHT+"] FONT WEIGHT: "+shortToHex(OFFSET_FONT_WEIGHT)+"\n");
buffer.append(" ["+OFFSET_ESCAPEMENT_TYPE+"] FONT ESCAPEMENT: "+shortToHex(OFFSET_ESCAPEMENT_TYPE)+"\n");
buffer.append(" ["+OFFSET_UNDERLINE_TYPE+"] FONT UNDERLINE: "+byteToHex(OFFSET_UNDERLINE_TYPE)+"\n");
buffer.append(" ["+(OFFSET_UNDERLINE_TYPE+1)+"] FONT NOT USED: "+byteToHex(OFFSET_UNDERLINE_TYPE+1)+"\n");
buffer.append(" ["+(OFFSET_UNDERLINE_TYPE+2)+"] FONT NOT USED: "+byteToHex(OFFSET_UNDERLINE_TYPE+2)+"\n");
buffer.append(" ["+(OFFSET_UNDERLINE_TYPE+3)+"] FONT NOT USED: "+byteToHex(OFFSET_UNDERLINE_TYPE+3)+"\n");
buffer.append(" ["+OFFSET_FONT_COLOR_INDEX+"] FONT COLIDX: "+intToHex(OFFSET_FONT_COLOR_INDEX)+"\n");
buffer.append(" ["+(OFFSET_FONT_COLOR_INDEX+4)+"] FONT NOT USED: "+intToHex(OFFSET_FONT_COLOR_INDEX+4)+"\n");
buffer.append(" ["+OFFSET_OPTION_FLAGS+"] FONT OPTIONS: "+intToHex(OFFSET_OPTION_FLAGS)+"\n");
buffer.append(" ["+OFFSET_ESCAPEMENT_TYPE_MODIFIED+"] FONT ESC MOD: "+intToHex(OFFSET_ESCAPEMENT_TYPE_MODIFIED)+"\n");
buffer.append(" ["+OFFSET_UNDERLINE_TYPE_MODIFIED+"] FONT UND MOD: "+intToHex(OFFSET_UNDERLINE_TYPE_MODIFIED)+"\n");
buffer.append(" ["+OFFSET_FONT_WEIGHT+"] FONT WGH MOD: "+intToHex(OFFSET_FONT_WEIGHT)+"\n");
buffer.append(" ["+OFFSET_NOT_USED+"] FONT NOT USED: "+intToHex(OFFSET_NOT_USED)+"\n");
buffer.append(" ["+(OFFSET_NOT_USED+4)+"] FONT NOT USED: "+intToHex(OFFSET_NOT_USED+4)+"\n");
buffer.append(" ["+(OFFSET_NOT_USED+8)+"] FONT NOT USED: "+intToHex(OFFSET_NOT_USED+8)+"\n");
buffer.append(" ["+OFFSET_FONT_FORMATING_END+"] FONT FORMATTING END: "+shortToHex(OFFSET_FONT_FORMATING_END)+"\n");
buffer.append(" ====\n");
buffer.append(" [/Font Formatting]\n");
return buffer.toString();
}
public Object clone()
{
FontFormatting rec = new FontFormatting();
@ -588,4 +588,18 @@ public class FontFormatting
}
return rec;
}
private String intToHex(int offset)
{
return Integer.toHexString(LittleEndian.getInt(record, offset));
}
private String shortToHex(int offset)
{
return Integer.toHexString(LittleEndian.getShort(record, offset)&0xFFFF);
}
private String byteToHex(int offset)
{
return Integer.toHexString(record[offset]&0xFF);
}
}

View File

@ -65,6 +65,11 @@ public final class HSSFBorderFormatting
borderFormatting = new BorderFormatting();
}
protected HSSFBorderFormatting(BorderFormatting borderFormatting)
{
this.borderFormatting = borderFormatting;
}
protected BorderFormatting getBorderFormattingBlock()
{
return borderFormatting;

View File

@ -17,8 +17,6 @@
package org.apache.poi.hssf.usermodel;
import java.util.List;
import org.apache.poi.hssf.model.FormulaParser;
import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.CFRuleRecord;
@ -40,9 +38,6 @@ import org.apache.poi.hssf.record.formula.Ptg;
public final class HSSFConditionalFormattingRule
{
private static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS;
private final CFRuleRecord cfRuleRecord;
private final Workbook workbook;
@ -73,6 +68,19 @@ public final class HSSFConditionalFormattingRule
FontFormatting block = fontFmt==null ? null : fontFmt.getFontFormattingBlock();
cfRuleRecord.setFontFormatting(block);
}
/**
* @return - font formatting object if defined, <code>null</code> otherwise
*/
public HSSFFontFormatting getFontFormatting()
{
FontFormatting ff = cfRuleRecord.getFontFormatting();
if ( ff == null ) {
return null;
}
return new HSSFFontFormatting(ff);
}
/**
* @param borderFmt pass <code>null</code> to signify 'border unchanged'
*/
@ -81,6 +89,17 @@ public final class HSSFConditionalFormattingRule
BorderFormatting block = borderFmt==null ? null : borderFmt.getBorderFormattingBlock();
cfRuleRecord.setBorderFormatting(block);
}
/**
* @return - border formatting object if defined, <code>null</code> otherwise
*/
public HSSFBorderFormatting getBorderFormatting()
{
BorderFormatting bf = cfRuleRecord.getBorderFormatting();
if ( bf == null ) {
return null;
}
return new HSSFBorderFormatting(bf);
}
/**
* @param patternFmt pass <code>null</code> to signify 'pattern unchanged'
*/
@ -89,6 +108,17 @@ public final class HSSFConditionalFormattingRule
PatternFormatting block = patternFmt==null ? null : patternFmt.getPatternFormattingBlock();
cfRuleRecord.setPatternFormatting(block);
}
/**
* @return - pattern formatting object if defined, <code>null</code> otherwise
*/
public HSSFPatternFormatting getPatternFormatting()
{
PatternFormatting pf = cfRuleRecord.getPatternFormatting();
if ( pf == null ) {
return null;
}
return new HSSFPatternFormatting(pf);
}
public String getFormula1()
{
@ -112,11 +142,9 @@ public final class HSSFConditionalFormattingRule
private String toFormulaString(Ptg[] parsedExpression)
{
String formula = null;
if(parsedExpression!=null)
{
formula = FormulaParser.toFormulaString(workbook, parsedExpression);
if(parsedExpression ==null) {
return null;
}
return formula;
return FormulaParser.toFormulaString(workbook, parsedExpression);
}
}

View File

@ -25,64 +25,51 @@ import org.apache.poi.hssf.record.cf.FontFormatting;
* @author Dmitriy Kumshayev
*
*/
public class HSSFFontFormatting
public final class HSSFFontFormatting
{
/**
* Escapement type - None
*/
public final static short SS_NONE = FontFormatting.SS_NONE;
/** Escapement type - None */
public final static short SS_NONE = FontFormatting.SS_NONE;
/** Escapement type - Superscript */
public final static short SS_SUPER = FontFormatting.SS_SUPER;
/** Escapement type - Subscript */
public final static short SS_SUB = FontFormatting.SS_SUB;
/**
* Escapement type - Superscript
*/
public final static short SS_SUPER = FontFormatting.SS_SUPER;
/** Underline type - None */
public final static byte U_NONE = FontFormatting.U_NONE;
/** Underline type - Single */
public final static byte U_SINGLE = FontFormatting.U_SINGLE;
/** Underline type - Double */
public final static byte U_DOUBLE = FontFormatting.U_DOUBLE;
/** Underline type - Single Accounting */
public final static byte U_SINGLE_ACCOUNTING = FontFormatting.U_SINGLE_ACCOUNTING;
/** Underline type - Double Accounting */
public final static byte U_DOUBLE_ACCOUNTING = FontFormatting.U_DOUBLE_ACCOUNTING;
/**
* Escapement type - Subscript
*/
public final static short SS_SUB = FontFormatting.SS_SUB;
/**
* Underline type - None
*/
public final static byte U_NONE = FontFormatting.U_NONE;
/**
* Underline type - Single
*/
public final static byte U_SINGLE = FontFormatting.U_SINGLE;
/**
* Underline type - Double
*/
public final static byte U_DOUBLE = FontFormatting.U_DOUBLE;
/**
* Underline type - Single Accounting
*/
public final static byte U_SINGLE_ACCOUNTING = FontFormatting.U_SINGLE_ACCOUNTING;
/**
* Underline type - Double Accounting
*/
public final static byte U_DOUBLE_ACCOUNTING = FontFormatting.U_DOUBLE_ACCOUNTING;
private FontFormatting fontFormatting;
private final FontFormatting fontFormatting;
public HSSFFontFormatting()
{
fontFormatting = new FontFormatting();
}
protected HSSFFontFormatting(FontFormatting ff)
{
fontFormatting = ff;
}
protected FontFormatting getFontFormattingBlock()
{
return fontFormatting;
}
/**
* get the type of super or subscript for the font
*
* @return super or subscript option
* @see #SS_NONE
* @see #SS_SUPER
* @see #SS_SUB
*/
/**
* get the type of super or subscript for the font
*
* @return super or subscript option
* @see #SS_NONE
* @see #SS_SUPER
* @see #SS_SUB
*/
public short getEscapementType()
{
return fontFormatting.getEscapementType();
@ -96,22 +83,22 @@ public class HSSFFontFormatting
return fontFormatting.getFontColorIndex();
}
/**
* gets the height of the font in 1/20th point units
*
* @return fontheight (in points/20); or -1 if not modified
*/
/**
* gets the height of the font in 1/20th point units
*
* @return fontheight (in points/20); or -1 if not modified
*/
public short getFontHeight()
{
return fontFormatting.getFontHeight();
}
/**
* get the font weight for this font (100-1000dec or 0x64-0x3e8). Default is
* 0x190 for normal and 0x2bc for bold
*
* @return bw - a number between 100-1000 for the fonts "boldness"
*/
/**
* get the font weight for this font (100-1000dec or 0x64-0x3e8). Default is
* 0x190 for normal and 0x2bc for bold
*
* @return bw - a number between 100-1000 for the fonts "boldness"
*/
public short getFontWeight()
{
@ -127,38 +114,30 @@ public class HSSFFontFormatting
return fontFormatting.getRawRecord();
}
/**
* get the type of underlining for the font
*
* @return font underlining type
*
* @see #U_NONE
* @see #U_SINGLE
* @see #U_DOUBLE
* @see #U_SINGLE_ACCOUNTING
* @see #U_DOUBLE_ACCOUNTING
*/
/**
* get the type of underlining for the font
*
* @return font underlining type
*
* @see #U_NONE
* @see #U_SINGLE
* @see #U_DOUBLE
* @see #U_SINGLE_ACCOUNTING
* @see #U_DOUBLE_ACCOUNTING
*/
public short getUnderlineType()
{
return fontFormatting.getUnderlineType();
}
/**
* get whether the font weight is set to bold or not
*
* @return bold - whether the font is bold or not
*/
/**
* get whether the font weight is set to bold or not
*
* @return bold - whether the font is bold or not
*/
public boolean isBold()
{
return fontFormatting.isBold();
}
/**
* @return whether the font is condense or not
*/
public boolean isCondenseOn()
{
return fontFormatting.isFontOutlineModified() && fontFormatting.isCondenseOn();
return fontFormatting.isFontWeightModified() && fontFormatting.isBold();
}
/**
@ -177,14 +156,6 @@ public class HSSFFontFormatting
return fontFormatting.isFontCancellationModified();
}
/**
* @return true if font condense type was modified from default
*/
public boolean isFontCondenseModified()
{
return fontFormatting.isFontCondenseModified();
}
/**
* @return true if font outline type was modified from default
*/
@ -249,66 +220,61 @@ public class HSSFFontFormatting
return fontFormatting.isUnderlineTypeModified();
}
/**
* set font style options.
*
* @param italic - if true, set posture style to italic, otherwise to normal
* @param bold- if true, set font weight to bold, otherwise to normal
*/
/**
* @return true if font weight was modified from default
*/
public boolean isFontWeightModified()
{
return fontFormatting.isFontWeightModified();
}
/**
* set font style options.
*
* @param italic - if true, set posture style to italic, otherwise to normal
* @param bold- if true, set font weight to bold, otherwise to normal
*/
public void setFontStyle(boolean italic, boolean bold)
{
boolean modified = italic || bold;
fontFormatting.setItalic(italic);
fontFormatting.setBold(bold);
fontFormatting.setFontStyleModified(modified);
boolean modified = italic || bold;
fontFormatting.setItalic(italic);
fontFormatting.setBold(bold);
fontFormatting.setFontStyleModified(modified);
fontFormatting.setFontWieghtModified(modified);
}
/**
* set font style options to default values (non-italic, non-bold)
*/
/**
* set font style options to default values (non-italic, non-bold)
*/
public void resetFontStyle()
{
setFontStyle(false,false);
}
/**
* set the escapement type for the font
*
* @param escapementType super or subscript option
* @see #SS_NONE
* @see #SS_SUPER
* @see #SS_SUB
*/
public void setCondense(boolean on)
{
fontFormatting.setCondense(on);
fontFormatting.setFontCondenseModified(on);
}
/**
* set the escapement type for the font
*
* @param escapementType super or subscript option
* @see #SS_NONE
* @see #SS_SUPER
* @see #SS_SUB
*/
/**
* set the escapement type for the font
*
* @param escapementType super or subscript option
* @see #SS_NONE
* @see #SS_SUPER
* @see #SS_SUB
*/
public void setEscapementType(short escapementType)
{
switch(escapementType)
{
case HSSFFontFormatting.SS_SUB:
case HSSFFontFormatting.SS_SUPER:
fontFormatting.setEscapementType(escapementType);
fontFormatting.setEscapementTypeModified(true);
break;
case HSSFFontFormatting.SS_NONE:
fontFormatting.setEscapementType(escapementType);
fontFormatting.setEscapementTypeModified(false);
break;
default:
}
switch(escapementType)
{
case HSSFFontFormatting.SS_SUB:
case HSSFFontFormatting.SS_SUPER:
fontFormatting.setEscapementType(escapementType);
fontFormatting.setEscapementTypeModified(true);
break;
case HSSFFontFormatting.SS_NONE:
fontFormatting.setEscapementType(escapementType);
fontFormatting.setEscapementTypeModified(false);
break;
default:
}
}
/**
@ -338,15 +304,6 @@ public class HSSFFontFormatting
fontFormatting.setFontColorIndex(fci);
}
/**
* @param modified
* @see org.apache.poi.hssf.record.cf.FontFormatting#setFontCondenseModified(boolean)
*/
public void setFontCondenseModified(boolean modified)
{
fontFormatting.setFontCondenseModified(modified);
}
/**
* @param height
* @see org.apache.poi.hssf.record.cf.FontFormatting#setFontHeight(short)
@ -413,35 +370,35 @@ public class HSSFFontFormatting
fontFormatting.setFontCancellationModified(strike);
}
/**
* set the type of underlining type for the font
*
* @param u super or subscript option
*
* @see #U_NONE
* @see #U_SINGLE
* @see #U_DOUBLE
* @see #U_SINGLE_ACCOUNTING
* @see #U_DOUBLE_ACCOUNTING
*/
/**
* set the type of underlining type for the font
*
* @param u super or subscript option
*
* @see #U_NONE
* @see #U_SINGLE
* @see #U_DOUBLE
* @see #U_SINGLE_ACCOUNTING
* @see #U_DOUBLE_ACCOUNTING
*/
public void setUnderlineType(short underlineType)
{
switch(underlineType)
{
case HSSFFontFormatting.U_SINGLE:
case HSSFFontFormatting.U_DOUBLE:
case HSSFFontFormatting.U_SINGLE_ACCOUNTING:
case HSSFFontFormatting.U_DOUBLE_ACCOUNTING:
fontFormatting.setUnderlineType(underlineType);
setUnderlineTypeModified(true);
break;
case HSSFFontFormatting.U_NONE:
fontFormatting.setUnderlineType(underlineType);
setUnderlineTypeModified(false);
break;
default:
}
switch(underlineType)
{
case HSSFFontFormatting.U_SINGLE:
case HSSFFontFormatting.U_DOUBLE:
case HSSFFontFormatting.U_SINGLE_ACCOUNTING:
case HSSFFontFormatting.U_DOUBLE_ACCOUNTING:
fontFormatting.setUnderlineType(underlineType);
setUnderlineTypeModified(true);
break;
case HSSFFontFormatting.U_NONE:
fontFormatting.setUnderlineType(underlineType);
setUnderlineTypeModified(false);
break;
default:
}
}
/**
@ -452,5 +409,4 @@ public class HSSFFontFormatting
{
fontFormatting.setUnderlineTypeModified(modified);
}
}

View File

@ -27,44 +27,44 @@ import org.apache.poi.hssf.record.cf.PatternFormatting;
*/
public class HSSFPatternFormatting
{
/** No background */
public final static short NO_FILL = PatternFormatting.NO_FILL;
/** Solidly filled */
public final static short SOLID_FOREGROUND = PatternFormatting.SOLID_FOREGROUND;
/** Small fine dots */
public final static short FINE_DOTS = PatternFormatting.FINE_DOTS;
/** Wide dots */
public final static short ALT_BARS = PatternFormatting.ALT_BARS;
/** Sparse dots */
public final static short SPARSE_DOTS = PatternFormatting.SPARSE_DOTS;
/** Thick horizontal bands */
public final static short THICK_HORZ_BANDS = PatternFormatting.THICK_HORZ_BANDS;
/** Thick vertical bands */
public final static short THICK_VERT_BANDS = PatternFormatting.THICK_VERT_BANDS;
/** Thick backward facing diagonals */
public final static short THICK_BACKWARD_DIAG = PatternFormatting.THICK_BACKWARD_DIAG;
/** Thick forward facing diagonals */
public final static short THICK_FORWARD_DIAG = PatternFormatting.THICK_FORWARD_DIAG;
/** Large spots */
public final static short BIG_SPOTS = PatternFormatting.BIG_SPOTS;
/** Brick-like layout */
public final static short BRICKS = PatternFormatting.BRICKS;
/** Thin horizontal bands */
public final static short THIN_HORZ_BANDS = PatternFormatting.THIN_HORZ_BANDS;
/** Thin vertical bands */
public final static short THIN_VERT_BANDS = PatternFormatting.THIN_VERT_BANDS;
/** Thin backward diagonal */
public final static short THIN_BACKWARD_DIAG = PatternFormatting.THIN_BACKWARD_DIAG;
/** Thin forward diagonal */
public final static short THIN_FORWARD_DIAG = PatternFormatting.THIN_FORWARD_DIAG;
/** Squares */
public final static short SQUARES = PatternFormatting.SQUARES;
/** Diamonds */
public final static short DIAMONDS = PatternFormatting.DIAMONDS;
/** Less Dots */
public final static short LESS_DOTS = PatternFormatting.LESS_DOTS;
/** Least Dots */
public final static short LEAST_DOTS = PatternFormatting.LEAST_DOTS;
/** No background */
public final static short NO_FILL = PatternFormatting.NO_FILL;
/** Solidly filled */
public final static short SOLID_FOREGROUND = PatternFormatting.SOLID_FOREGROUND;
/** Small fine dots */
public final static short FINE_DOTS = PatternFormatting.FINE_DOTS;
/** Wide dots */
public final static short ALT_BARS = PatternFormatting.ALT_BARS;
/** Sparse dots */
public final static short SPARSE_DOTS = PatternFormatting.SPARSE_DOTS;
/** Thick horizontal bands */
public final static short THICK_HORZ_BANDS = PatternFormatting.THICK_HORZ_BANDS;
/** Thick vertical bands */
public final static short THICK_VERT_BANDS = PatternFormatting.THICK_VERT_BANDS;
/** Thick backward facing diagonals */
public final static short THICK_BACKWARD_DIAG = PatternFormatting.THICK_BACKWARD_DIAG;
/** Thick forward facing diagonals */
public final static short THICK_FORWARD_DIAG = PatternFormatting.THICK_FORWARD_DIAG;
/** Large spots */
public final static short BIG_SPOTS = PatternFormatting.BIG_SPOTS;
/** Brick-like layout */
public final static short BRICKS = PatternFormatting.BRICKS;
/** Thin horizontal bands */
public final static short THIN_HORZ_BANDS = PatternFormatting.THIN_HORZ_BANDS;
/** Thin vertical bands */
public final static short THIN_VERT_BANDS = PatternFormatting.THIN_VERT_BANDS;
/** Thin backward diagonal */
public final static short THIN_BACKWARD_DIAG = PatternFormatting.THIN_BACKWARD_DIAG;
/** Thin forward diagonal */
public final static short THIN_FORWARD_DIAG = PatternFormatting.THIN_FORWARD_DIAG;
/** Squares */
public final static short SQUARES = PatternFormatting.SQUARES;
/** Diamonds */
public final static short DIAMONDS = PatternFormatting.DIAMONDS;
/** Less Dots */
public final static short LESS_DOTS = PatternFormatting.LESS_DOTS;
/** Least Dots */
public final static short LEAST_DOTS = PatternFormatting.LEAST_DOTS;
private PatternFormatting patternFormatting;
@ -72,6 +72,10 @@ public class HSSFPatternFormatting
{
patternFormatting = new PatternFormatting();
}
protected HSSFPatternFormatting(PatternFormatting patternFormatting)
{
this.patternFormatting = patternFormatting;
}
protected PatternFormatting getPatternFormattingBlock()
{

View File

@ -182,14 +182,13 @@ public final class TestCFRuleRecord extends TestCase
// Check for defaults
assertFalse(fontFormatting.isEscapementTypeModified());
assertFalse(fontFormatting.isFontCancellationModified());
assertFalse(fontFormatting.isFontCondenseModified());
assertFalse(fontFormatting.isFontOutlineModified());
assertFalse(fontFormatting.isFontShadowModified());
assertFalse(fontFormatting.isFontStyleModified());
assertFalse(fontFormatting.isUnderlineTypeModified());
assertFalse(fontFormatting.isFontWeightModified());
assertFalse(fontFormatting.isBold());
assertFalse(fontFormatting.isCondenseOn());
assertFalse(fontFormatting.isItalic());
assertFalse(fontFormatting.isOutlineOn());
assertFalse(fontFormatting.isShadowOn());
@ -198,7 +197,7 @@ public final class TestCFRuleRecord extends TestCase
assertEquals(0, fontFormatting.getEscapementType());
assertEquals(-1, fontFormatting.getFontColorIndex());
assertEquals(-1, fontFormatting.getFontHeight());
assertEquals(400, fontFormatting.getFontWeight());
assertEquals(0, fontFormatting.getFontWeight());
assertEquals(0, fontFormatting.getUnderlineType());
fontFormatting.setBold(true);
@ -206,11 +205,6 @@ public final class TestCFRuleRecord extends TestCase
fontFormatting.setBold(false);
assertFalse(fontFormatting.isBold());
fontFormatting.setCondense(true);
assertTrue(fontFormatting.isCondenseOn());
fontFormatting.setCondense(false);
assertFalse(fontFormatting.isCondenseOn());
fontFormatting.setEscapementType(FontFormatting.SS_SUB);
assertEquals(FontFormatting.SS_SUB, fontFormatting.getEscapementType());
fontFormatting.setEscapementType(FontFormatting.SS_SUPER);
@ -223,6 +217,11 @@ public final class TestCFRuleRecord extends TestCase
fontFormatting.setEscapementTypeModified(true);
assertTrue(fontFormatting.isEscapementTypeModified());
fontFormatting.setFontWieghtModified(false);
assertFalse(fontFormatting.isFontWeightModified());
fontFormatting.setFontWieghtModified(true);
assertTrue(fontFormatting.isFontWeightModified());
fontFormatting.setFontCancellationModified(false);
assertFalse(fontFormatting.isFontCancellationModified());
fontFormatting.setFontCancellationModified(true);
@ -231,11 +230,6 @@ public final class TestCFRuleRecord extends TestCase
fontFormatting.setFontColorIndex((short)10);
assertEquals(10,fontFormatting.getFontColorIndex());
fontFormatting.setFontCondenseModified(false);
assertFalse(fontFormatting.isFontCondenseModified());
fontFormatting.setFontCondenseModified(true);
assertTrue(fontFormatting.isFontCondenseModified());
fontFormatting.setFontHeight((short)100);
assertEquals(100,fontFormatting.getFontHeight());

View File

@ -28,7 +28,7 @@ import org.apache.poi.hssf.util.Region;
*/
public final class TestHSSFConditionalFormatting extends TestCase
{
public void testLastAndFirstColumns()
public void testCreateCF()
{
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
@ -82,9 +82,27 @@ public final class TestHSSFConditionalFormatting extends TestCase
HSSFConditionalFormattingRule rule1 = cf.getRule(0);
assertEquals("7",rule1.getFormula1());
assertNull(rule1.getFormula2());
HSSFFontFormatting r1fp = rule1.getFontFormatting();
assertNotNull(r1fp);
assertTrue(r1fp.isItalic());
assertFalse(r1fp.isBold());
HSSFBorderFormatting r1bf = rule1.getBorderFormatting();
assertNotNull(r1bf);
assertEquals(HSSFBorderFormatting.BORDER_THIN, r1bf.getBorderBottom());
assertEquals(HSSFBorderFormatting.BORDER_THICK,r1bf.getBorderTop());
assertEquals(HSSFBorderFormatting.BORDER_DASHED,r1bf.getBorderLeft());
assertEquals(HSSFBorderFormatting.BORDER_DOTTED,r1bf.getBorderRight());
HSSFPatternFormatting r1pf = rule1.getPatternFormatting();
assertNotNull(r1pf);
assertEquals(HSSFColor.RED.index,r1pf.getFillBackgroundColor());
HSSFConditionalFormattingRule rule2 = cf.getRule(1);
assertEquals("2",rule2.getFormula2());
assertEquals("1",rule2.getFormula1());
}
}