1. fixed HSSFCell.setCellFormula to call HSSFFormulaParser.parse before any cell modifications, if it fails the cell must be left in the state prior to the invocation. 2. added @throws javadoc to HSSFRow.createCell and XSSFRow.createCell, see bug #10393 3. fixed incorrect condition type in CFRuleRecord if the rule is a formula
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@726049 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
015af7c141
commit
13860fc475
@ -125,8 +125,6 @@ public final class CFRuleRecord extends StandardRecord {
|
|||||||
|
|
||||||
private CFRuleRecord(byte conditionType, byte comparisonOperation, Ptg[] formula1, Ptg[] formula2) {
|
private CFRuleRecord(byte conditionType, byte comparisonOperation, Ptg[] formula1, Ptg[] formula2) {
|
||||||
this(conditionType, comparisonOperation);
|
this(conditionType, comparisonOperation);
|
||||||
field_1_condition_type = CONDITION_TYPE_CELL_VALUE_IS;
|
|
||||||
field_2_comparison_operator = comparisonOperation;
|
|
||||||
field_17_formula1 = Formula.create(formula1);
|
field_17_formula1 = Formula.create(formula1);
|
||||||
field_18_formula2 = Formula.create(formula2);
|
field_18_formula2 = Formula.create(formula2);
|
||||||
}
|
}
|
||||||
@ -485,6 +483,7 @@ public final class CFRuleRecord extends StandardRecord {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
buffer.append("[CFRULE]\n");
|
buffer.append("[CFRULE]\n");
|
||||||
|
buffer.append(" .condition_type ="+field_1_condition_type);
|
||||||
buffer.append(" OPTION FLAGS=0x"+Integer.toHexString(getOptions()));
|
buffer.append(" OPTION FLAGS=0x"+Integer.toHexString(getOptions()));
|
||||||
if (false) {
|
if (false) {
|
||||||
if (containsFontFormattingBlock()) {
|
if (containsFontFormattingBlock()) {
|
||||||
|
@ -578,6 +578,7 @@ public class HSSFCell implements Cell {
|
|||||||
setCellType(CELL_TYPE_BLANK, false, row, col, styleIndex);
|
setCellType(CELL_TYPE_BLANK, false, row, col, styleIndex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Ptg[] ptgs = HSSFFormulaParser.parse(formula, book);
|
||||||
setCellType(CELL_TYPE_FORMULA, false, row, col, styleIndex);
|
setCellType(CELL_TYPE_FORMULA, false, row, col, styleIndex);
|
||||||
FormulaRecordAggregate agg = (FormulaRecordAggregate) record;
|
FormulaRecordAggregate agg = (FormulaRecordAggregate) record;
|
||||||
FormulaRecord frec = agg.getFormulaRecord();
|
FormulaRecord frec = agg.getFormulaRecord();
|
||||||
@ -588,7 +589,6 @@ public class HSSFCell implements Cell {
|
|||||||
if (agg.getXFIndex() == (short)0) {
|
if (agg.getXFIndex() == (short)0) {
|
||||||
agg.setXFIndex((short) 0x0f);
|
agg.setXFIndex((short) 0x0f);
|
||||||
}
|
}
|
||||||
Ptg[] ptgs = HSSFFormulaParser.parse(formula, book);
|
|
||||||
agg.setParsedExpression(ptgs);
|
agg.setParsedExpression(ptgs);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -896,11 +896,11 @@ public class HSSFCell implements Cell {
|
|||||||
*/
|
*/
|
||||||
private void checkBounds(int cellNum) {
|
private void checkBounds(int cellNum) {
|
||||||
if (cellNum > 255) {
|
if (cellNum > 255) {
|
||||||
throw new RuntimeException("You cannot have more than 255 columns "+
|
throw new IllegalArgumentException("You cannot have more than 255 columns "+
|
||||||
"in a given row (IV). Because Excel can't handle it");
|
"in a given row (IV). Because Excel can't handle it");
|
||||||
}
|
}
|
||||||
else if (cellNum < 0) {
|
else if (cellNum < 0) {
|
||||||
throw new RuntimeException("You cannot reference columns with an index of less then 0.");
|
throw new IllegalArgumentException("You cannot reference columns with an index of less then 0.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,6 +114,8 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* @param column - the column number this cell represents
|
* @param column - the column number this cell represents
|
||||||
*
|
*
|
||||||
* @return HSSFCell a high level representation of the created cell.
|
* @return HSSFCell a high level representation of the created cell.
|
||||||
|
* @throws IllegalArgumentException if columnIndex < 0 or greater than 255,
|
||||||
|
* the maximum number of columns supported by the Excel binary format (.xls)
|
||||||
*/
|
*/
|
||||||
public HSSFCell createCell(int column)
|
public HSSFCell createCell(int column)
|
||||||
{
|
{
|
||||||
@ -129,6 +131,8 @@ public final class HSSFRow implements Comparable, Row {
|
|||||||
* @param columnIndex - the column number this cell represents
|
* @param columnIndex - the column number this cell represents
|
||||||
*
|
*
|
||||||
* @return HSSFCell a high level representation of the created cell.
|
* @return HSSFCell a high level representation of the created cell.
|
||||||
|
* @throws IllegalArgumentException if columnIndex < 0 or greater than 255,
|
||||||
|
* the maximum number of columns supported by the Excel binary format (.xls)
|
||||||
*/
|
*/
|
||||||
public HSSFCell createCell(int columnIndex, int type)
|
public HSSFCell createCell(int columnIndex, int type)
|
||||||
{
|
{
|
||||||
|
@ -33,7 +33,8 @@ public interface Row extends Iterable<Cell> {
|
|||||||
*
|
*
|
||||||
* @param column - the column number this cell represents
|
* @param column - the column number this cell represents
|
||||||
* @return Cell a high level representation of the created cell.
|
* @return Cell a high level representation of the created cell.
|
||||||
* @throws IllegalArgumentException if columnIndex < 0
|
* @throws IllegalArgumentException if columnIndex < 0 or greater than the maximum number of supported columns
|
||||||
|
* (255 for *.xls, 1048576 for *.xlsx)
|
||||||
*/
|
*/
|
||||||
Cell createCell(int column);
|
Cell createCell(int column);
|
||||||
|
|
||||||
@ -45,7 +46,8 @@ public interface Row extends Iterable<Cell> {
|
|||||||
*
|
*
|
||||||
* @param column - the column number this cell represents
|
* @param column - the column number this cell represents
|
||||||
* @return Cell a high level representation of the created cell.
|
* @return Cell a high level representation of the created cell.
|
||||||
* @throws IllegalArgumentException if columnIndex < 0
|
* @throws IllegalArgumentException if columnIndex < 0 or greate than a maximum number of supported columns
|
||||||
|
* (255 for *.xls, 1048576 for *.xlsx)
|
||||||
*/
|
*/
|
||||||
Cell createCell(int column, int type);
|
Cell createCell(int column, int type);
|
||||||
|
|
||||||
|
@ -134,7 +134,8 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
|
|||||||
* </p>
|
* </p>
|
||||||
* @param columnIndex - the column number this cell represents
|
* @param columnIndex - the column number this cell represents
|
||||||
* @return Cell a high level representation of the created cell.
|
* @return Cell a high level representation of the created cell.
|
||||||
* @throws IllegalArgumentException if columnIndex < 0
|
* @throws IllegalArgumentException if columnIndex < 0 or greater than 16384,
|
||||||
|
* the maximum number of columns supported by the SpreadsheetML format (.xlsx)
|
||||||
*/
|
*/
|
||||||
public XSSFCell createCell(int columnIndex) {
|
public XSSFCell createCell(int columnIndex) {
|
||||||
return createCell(columnIndex, Cell.CELL_TYPE_BLANK);
|
return createCell(columnIndex, Cell.CELL_TYPE_BLANK);
|
||||||
@ -146,7 +147,8 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
|
|||||||
* @param columnIndex - the column number this cell represents
|
* @param columnIndex - the column number this cell represents
|
||||||
* @param type - the cell's data type
|
* @param type - the cell's data type
|
||||||
* @return XSSFCell a high level representation of the created cell.
|
* @return XSSFCell a high level representation of the created cell.
|
||||||
* @throws IllegalArgumentException if columnIndex < 0 or if the specified cell type is invalid
|
* @throws IllegalArgumentException if the specified cell type is invalid, columnIndex < 0
|
||||||
|
* or greater than 16384, the maximum number of columns supported by the SpreadsheetML format (.xlsx)
|
||||||
* @see Cell#CELL_TYPE_BLANK
|
* @see Cell#CELL_TYPE_BLANK
|
||||||
* @see Cell#CELL_TYPE_BOOLEAN
|
* @see Cell#CELL_TYPE_BOOLEAN
|
||||||
* @see Cell#CELL_TYPE_ERROR
|
* @see Cell#CELL_TYPE_ERROR
|
||||||
|
@ -30,6 +30,7 @@ import org.apache.poi.hssf.record.formula.RefPtg;
|
|||||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
import org.apache.poi.hssf.util.HSSFColor;
|
import org.apache.poi.hssf.util.HSSFColor;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndian;
|
||||||
|
import org.apache.poi.ss.formula.Formula;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the serialization and deserialization of the TestCFRuleRecord
|
* Tests the serialization and deserialization of the TestCFRuleRecord
|
||||||
@ -39,322 +40,344 @@ import org.apache.poi.util.LittleEndian;
|
|||||||
*/
|
*/
|
||||||
public final class TestCFRuleRecord extends TestCase
|
public final class TestCFRuleRecord extends TestCase
|
||||||
{
|
{
|
||||||
|
public void testConstructors ()
|
||||||
public void testCreateCFRuleRecord ()
|
{
|
||||||
{
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
|
||||||
CFRuleRecord record = CFRuleRecord.create(workbook, "7");
|
CFRuleRecord rule1 = CFRuleRecord.create(workbook, "7");
|
||||||
testCFRuleRecord(record);
|
assertEquals(CFRuleRecord.CONDITION_TYPE_FORMULA, rule1.getConditionType());
|
||||||
|
assertEquals(ComparisonOperator.NO_COMPARISON, rule1.getComparisonOperation());
|
||||||
// Serialize
|
assertNotNull(rule1.getParsedExpression1());
|
||||||
byte [] serializedRecord = record.serialize();
|
assertSame(Ptg.EMPTY_PTG_ARRAY, rule1.getParsedExpression2());
|
||||||
|
|
||||||
// Strip header
|
CFRuleRecord rule2 = CFRuleRecord.create(workbook, ComparisonOperator.BETWEEN, "2", "5");
|
||||||
byte [] recordData = new byte[serializedRecord.length-4];
|
assertEquals(CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS, rule2.getConditionType());
|
||||||
System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length);
|
assertEquals(ComparisonOperator.BETWEEN, rule2.getComparisonOperation());
|
||||||
|
assertNotNull(rule2.getParsedExpression1());
|
||||||
// Deserialize
|
assertNotNull(rule2.getParsedExpression2());
|
||||||
record = new CFRuleRecord(TestcaseRecordInputStream.create(CFRuleRecord.sid, recordData));
|
|
||||||
|
CFRuleRecord rule3 = CFRuleRecord.create(workbook, ComparisonOperator.EQUAL, null, null);
|
||||||
// Serialize again
|
assertEquals(CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS, rule3.getConditionType());
|
||||||
byte[] output = record.serialize();
|
assertEquals(ComparisonOperator.EQUAL, rule3.getComparisonOperation());
|
||||||
|
assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2());
|
||||||
// Compare
|
assertSame(Ptg.EMPTY_PTG_ARRAY, rule3.getParsedExpression2());
|
||||||
assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength
|
}
|
||||||
|
|
||||||
for (int i = 0; i < recordData.length;i++)
|
public void testCreateCFRuleRecord ()
|
||||||
{
|
{
|
||||||
assertEquals("CFRuleRecord doesn't match", recordData[i], output[i+4]);
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||||
}
|
CFRuleRecord record = CFRuleRecord.create(workbook, "7");
|
||||||
}
|
testCFRuleRecord(record);
|
||||||
|
|
||||||
private void testCFRuleRecord(CFRuleRecord record)
|
// Serialize
|
||||||
{
|
byte [] serializedRecord = record.serialize();
|
||||||
FontFormatting fontFormatting = new FontFormatting();
|
|
||||||
testFontFormattingAccessors(fontFormatting);
|
// Strip header
|
||||||
assertFalse(record.containsFontFormattingBlock());
|
byte [] recordData = new byte[serializedRecord.length-4];
|
||||||
record.setFontFormatting(fontFormatting);
|
System.arraycopy(serializedRecord, 4, recordData, 0, recordData.length);
|
||||||
assertTrue(record.containsFontFormattingBlock());
|
|
||||||
|
// Deserialize
|
||||||
BorderFormatting borderFormatting = new BorderFormatting();
|
record = new CFRuleRecord(TestcaseRecordInputStream.create(CFRuleRecord.sid, recordData));
|
||||||
testBorderFormattingAccessors(borderFormatting);
|
|
||||||
assertFalse(record.containsBorderFormattingBlock());
|
// Serialize again
|
||||||
record.setBorderFormatting(borderFormatting);
|
byte[] output = record.serialize();
|
||||||
assertTrue(record.containsBorderFormattingBlock());
|
|
||||||
|
// Compare
|
||||||
assertFalse(record.isLeftBorderModified());
|
assertEquals("Output size", recordData.length+4, output.length); //includes sid+recordlength
|
||||||
record.setLeftBorderModified(true);
|
|
||||||
assertTrue(record.isLeftBorderModified());
|
for (int i = 0; i < recordData.length;i++)
|
||||||
|
{
|
||||||
assertFalse(record.isRightBorderModified());
|
assertEquals("CFRuleRecord doesn't match", recordData[i], output[i+4]);
|
||||||
record.setRightBorderModified(true);
|
}
|
||||||
assertTrue(record.isRightBorderModified());
|
}
|
||||||
|
|
||||||
assertFalse(record.isTopBorderModified());
|
private void testCFRuleRecord(CFRuleRecord record)
|
||||||
record.setTopBorderModified(true);
|
{
|
||||||
assertTrue(record.isTopBorderModified());
|
FontFormatting fontFormatting = new FontFormatting();
|
||||||
|
testFontFormattingAccessors(fontFormatting);
|
||||||
assertFalse(record.isBottomBorderModified());
|
assertFalse(record.containsFontFormattingBlock());
|
||||||
record.setBottomBorderModified(true);
|
record.setFontFormatting(fontFormatting);
|
||||||
assertTrue(record.isBottomBorderModified());
|
assertTrue(record.containsFontFormattingBlock());
|
||||||
|
|
||||||
assertFalse(record.isTopLeftBottomRightBorderModified());
|
BorderFormatting borderFormatting = new BorderFormatting();
|
||||||
record.setTopLeftBottomRightBorderModified(true);
|
testBorderFormattingAccessors(borderFormatting);
|
||||||
assertTrue(record.isTopLeftBottomRightBorderModified());
|
assertFalse(record.containsBorderFormattingBlock());
|
||||||
|
record.setBorderFormatting(borderFormatting);
|
||||||
assertFalse(record.isBottomLeftTopRightBorderModified());
|
assertTrue(record.containsBorderFormattingBlock());
|
||||||
record.setBottomLeftTopRightBorderModified(true);
|
|
||||||
assertTrue(record.isBottomLeftTopRightBorderModified());
|
assertFalse(record.isLeftBorderModified());
|
||||||
|
record.setLeftBorderModified(true);
|
||||||
|
assertTrue(record.isLeftBorderModified());
|
||||||
PatternFormatting patternFormatting = new PatternFormatting();
|
|
||||||
testPatternFormattingAccessors(patternFormatting);
|
assertFalse(record.isRightBorderModified());
|
||||||
assertFalse(record.containsPatternFormattingBlock());
|
record.setRightBorderModified(true);
|
||||||
record.setPatternFormatting(patternFormatting);
|
assertTrue(record.isRightBorderModified());
|
||||||
assertTrue(record.containsPatternFormattingBlock());
|
|
||||||
|
assertFalse(record.isTopBorderModified());
|
||||||
assertFalse(record.isPatternBackgroundColorModified());
|
record.setTopBorderModified(true);
|
||||||
record.setPatternBackgroundColorModified(true);
|
assertTrue(record.isTopBorderModified());
|
||||||
assertTrue(record.isPatternBackgroundColorModified());
|
|
||||||
|
assertFalse(record.isBottomBorderModified());
|
||||||
assertFalse(record.isPatternColorModified());
|
record.setBottomBorderModified(true);
|
||||||
record.setPatternColorModified(true);
|
assertTrue(record.isBottomBorderModified());
|
||||||
assertTrue(record.isPatternColorModified());
|
|
||||||
|
assertFalse(record.isTopLeftBottomRightBorderModified());
|
||||||
assertFalse(record.isPatternStyleModified());
|
record.setTopLeftBottomRightBorderModified(true);
|
||||||
record.setPatternStyleModified(true);
|
assertTrue(record.isTopLeftBottomRightBorderModified());
|
||||||
assertTrue(record.isPatternStyleModified());
|
|
||||||
}
|
assertFalse(record.isBottomLeftTopRightBorderModified());
|
||||||
|
record.setBottomLeftTopRightBorderModified(true);
|
||||||
private void testPatternFormattingAccessors(PatternFormatting patternFormatting)
|
assertTrue(record.isBottomLeftTopRightBorderModified());
|
||||||
{
|
|
||||||
patternFormatting.setFillBackgroundColor(HSSFColor.GREEN.index);
|
|
||||||
assertEquals(HSSFColor.GREEN.index,patternFormatting.getFillBackgroundColor());
|
PatternFormatting patternFormatting = new PatternFormatting();
|
||||||
|
testPatternFormattingAccessors(patternFormatting);
|
||||||
patternFormatting.setFillForegroundColor(HSSFColor.INDIGO.index);
|
assertFalse(record.containsPatternFormattingBlock());
|
||||||
assertEquals(HSSFColor.INDIGO.index,patternFormatting.getFillForegroundColor());
|
record.setPatternFormatting(patternFormatting);
|
||||||
|
assertTrue(record.containsPatternFormattingBlock());
|
||||||
patternFormatting.setFillPattern(PatternFormatting.DIAMONDS);
|
|
||||||
assertEquals(PatternFormatting.DIAMONDS,patternFormatting.getFillPattern());
|
assertFalse(record.isPatternBackgroundColorModified());
|
||||||
}
|
record.setPatternBackgroundColorModified(true);
|
||||||
|
assertTrue(record.isPatternBackgroundColorModified());
|
||||||
private void testBorderFormattingAccessors(BorderFormatting borderFormatting)
|
|
||||||
{
|
assertFalse(record.isPatternColorModified());
|
||||||
borderFormatting.setBackwardDiagonalOn(false);
|
record.setPatternColorModified(true);
|
||||||
assertFalse(borderFormatting.isBackwardDiagonalOn());
|
assertTrue(record.isPatternColorModified());
|
||||||
borderFormatting.setBackwardDiagonalOn(true);
|
|
||||||
assertTrue(borderFormatting.isBackwardDiagonalOn());
|
assertFalse(record.isPatternStyleModified());
|
||||||
|
record.setPatternStyleModified(true);
|
||||||
borderFormatting.setBorderBottom(BorderFormatting.BORDER_DOTTED);
|
assertTrue(record.isPatternStyleModified());
|
||||||
assertEquals(BorderFormatting.BORDER_DOTTED, borderFormatting.getBorderBottom());
|
}
|
||||||
|
|
||||||
borderFormatting.setBorderDiagonal(BorderFormatting.BORDER_MEDIUM);
|
private void testPatternFormattingAccessors(PatternFormatting patternFormatting)
|
||||||
assertEquals(BorderFormatting.BORDER_MEDIUM, borderFormatting.getBorderDiagonal());
|
{
|
||||||
|
patternFormatting.setFillBackgroundColor(HSSFColor.GREEN.index);
|
||||||
borderFormatting.setBorderLeft(BorderFormatting.BORDER_MEDIUM_DASH_DOT_DOT);
|
assertEquals(HSSFColor.GREEN.index,patternFormatting.getFillBackgroundColor());
|
||||||
assertEquals(BorderFormatting.BORDER_MEDIUM_DASH_DOT_DOT, borderFormatting.getBorderLeft());
|
|
||||||
|
patternFormatting.setFillForegroundColor(HSSFColor.INDIGO.index);
|
||||||
borderFormatting.setBorderRight(BorderFormatting.BORDER_MEDIUM_DASHED);
|
assertEquals(HSSFColor.INDIGO.index,patternFormatting.getFillForegroundColor());
|
||||||
assertEquals(BorderFormatting.BORDER_MEDIUM_DASHED, borderFormatting.getBorderRight());
|
|
||||||
|
patternFormatting.setFillPattern(PatternFormatting.DIAMONDS);
|
||||||
borderFormatting.setBorderTop(BorderFormatting.BORDER_HAIR);
|
assertEquals(PatternFormatting.DIAMONDS,patternFormatting.getFillPattern());
|
||||||
assertEquals(BorderFormatting.BORDER_HAIR, borderFormatting.getBorderTop());
|
}
|
||||||
|
|
||||||
borderFormatting.setBottomBorderColor(HSSFColor.AQUA.index);
|
private void testBorderFormattingAccessors(BorderFormatting borderFormatting)
|
||||||
assertEquals(HSSFColor.AQUA.index, borderFormatting.getBottomBorderColor());
|
{
|
||||||
|
borderFormatting.setBackwardDiagonalOn(false);
|
||||||
borderFormatting.setDiagonalBorderColor(HSSFColor.RED.index);
|
assertFalse(borderFormatting.isBackwardDiagonalOn());
|
||||||
assertEquals(HSSFColor.RED.index, borderFormatting.getDiagonalBorderColor());
|
borderFormatting.setBackwardDiagonalOn(true);
|
||||||
|
assertTrue(borderFormatting.isBackwardDiagonalOn());
|
||||||
assertFalse(borderFormatting.isForwardDiagonalOn());
|
|
||||||
borderFormatting.setForwardDiagonalOn(true);
|
borderFormatting.setBorderBottom(BorderFormatting.BORDER_DOTTED);
|
||||||
assertTrue(borderFormatting.isForwardDiagonalOn());
|
assertEquals(BorderFormatting.BORDER_DOTTED, borderFormatting.getBorderBottom());
|
||||||
|
|
||||||
borderFormatting.setLeftBorderColor(HSSFColor.BLACK.index);
|
borderFormatting.setBorderDiagonal(BorderFormatting.BORDER_MEDIUM);
|
||||||
assertEquals(HSSFColor.BLACK.index, borderFormatting.getLeftBorderColor());
|
assertEquals(BorderFormatting.BORDER_MEDIUM, borderFormatting.getBorderDiagonal());
|
||||||
|
|
||||||
borderFormatting.setRightBorderColor(HSSFColor.BLUE.index);
|
borderFormatting.setBorderLeft(BorderFormatting.BORDER_MEDIUM_DASH_DOT_DOT);
|
||||||
assertEquals(HSSFColor.BLUE.index, borderFormatting.getRightBorderColor());
|
assertEquals(BorderFormatting.BORDER_MEDIUM_DASH_DOT_DOT, borderFormatting.getBorderLeft());
|
||||||
|
|
||||||
borderFormatting.setTopBorderColor(HSSFColor.GOLD.index);
|
borderFormatting.setBorderRight(BorderFormatting.BORDER_MEDIUM_DASHED);
|
||||||
assertEquals(HSSFColor.GOLD.index, borderFormatting.getTopBorderColor());
|
assertEquals(BorderFormatting.BORDER_MEDIUM_DASHED, borderFormatting.getBorderRight());
|
||||||
}
|
|
||||||
|
borderFormatting.setBorderTop(BorderFormatting.BORDER_HAIR);
|
||||||
|
assertEquals(BorderFormatting.BORDER_HAIR, borderFormatting.getBorderTop());
|
||||||
private void testFontFormattingAccessors(FontFormatting fontFormatting)
|
|
||||||
{
|
borderFormatting.setBottomBorderColor(HSSFColor.AQUA.index);
|
||||||
// Check for defaults
|
assertEquals(HSSFColor.AQUA.index, borderFormatting.getBottomBorderColor());
|
||||||
assertFalse(fontFormatting.isEscapementTypeModified());
|
|
||||||
assertFalse(fontFormatting.isFontCancellationModified());
|
borderFormatting.setDiagonalBorderColor(HSSFColor.RED.index);
|
||||||
assertFalse(fontFormatting.isFontOutlineModified());
|
assertEquals(HSSFColor.RED.index, borderFormatting.getDiagonalBorderColor());
|
||||||
assertFalse(fontFormatting.isFontShadowModified());
|
|
||||||
assertFalse(fontFormatting.isFontStyleModified());
|
assertFalse(borderFormatting.isForwardDiagonalOn());
|
||||||
assertFalse(fontFormatting.isUnderlineTypeModified());
|
borderFormatting.setForwardDiagonalOn(true);
|
||||||
assertFalse(fontFormatting.isFontWeightModified());
|
assertTrue(borderFormatting.isForwardDiagonalOn());
|
||||||
|
|
||||||
assertFalse(fontFormatting.isBold());
|
borderFormatting.setLeftBorderColor(HSSFColor.BLACK.index);
|
||||||
assertFalse(fontFormatting.isItalic());
|
assertEquals(HSSFColor.BLACK.index, borderFormatting.getLeftBorderColor());
|
||||||
assertFalse(fontFormatting.isOutlineOn());
|
|
||||||
assertFalse(fontFormatting.isShadowOn());
|
borderFormatting.setRightBorderColor(HSSFColor.BLUE.index);
|
||||||
assertFalse(fontFormatting.isStruckout());
|
assertEquals(HSSFColor.BLUE.index, borderFormatting.getRightBorderColor());
|
||||||
|
|
||||||
assertEquals(0, fontFormatting.getEscapementType());
|
borderFormatting.setTopBorderColor(HSSFColor.GOLD.index);
|
||||||
assertEquals(-1, fontFormatting.getFontColorIndex());
|
assertEquals(HSSFColor.GOLD.index, borderFormatting.getTopBorderColor());
|
||||||
assertEquals(-1, fontFormatting.getFontHeight());
|
}
|
||||||
assertEquals(0, fontFormatting.getFontWeight());
|
|
||||||
assertEquals(0, fontFormatting.getUnderlineType());
|
|
||||||
|
private void testFontFormattingAccessors(FontFormatting fontFormatting)
|
||||||
fontFormatting.setBold(true);
|
{
|
||||||
assertTrue(fontFormatting.isBold());
|
// Check for defaults
|
||||||
fontFormatting.setBold(false);
|
assertFalse(fontFormatting.isEscapementTypeModified());
|
||||||
assertFalse(fontFormatting.isBold());
|
assertFalse(fontFormatting.isFontCancellationModified());
|
||||||
|
assertFalse(fontFormatting.isFontOutlineModified());
|
||||||
fontFormatting.setEscapementType(FontFormatting.SS_SUB);
|
assertFalse(fontFormatting.isFontShadowModified());
|
||||||
assertEquals(FontFormatting.SS_SUB, fontFormatting.getEscapementType());
|
assertFalse(fontFormatting.isFontStyleModified());
|
||||||
fontFormatting.setEscapementType(FontFormatting.SS_SUPER);
|
assertFalse(fontFormatting.isUnderlineTypeModified());
|
||||||
assertEquals(FontFormatting.SS_SUPER, fontFormatting.getEscapementType());
|
assertFalse(fontFormatting.isFontWeightModified());
|
||||||
fontFormatting.setEscapementType(FontFormatting.SS_NONE);
|
|
||||||
assertEquals(FontFormatting.SS_NONE, fontFormatting.getEscapementType());
|
assertFalse(fontFormatting.isBold());
|
||||||
|
assertFalse(fontFormatting.isItalic());
|
||||||
fontFormatting.setEscapementTypeModified(false);
|
assertFalse(fontFormatting.isOutlineOn());
|
||||||
assertFalse(fontFormatting.isEscapementTypeModified());
|
assertFalse(fontFormatting.isShadowOn());
|
||||||
fontFormatting.setEscapementTypeModified(true);
|
assertFalse(fontFormatting.isStruckout());
|
||||||
assertTrue(fontFormatting.isEscapementTypeModified());
|
|
||||||
|
assertEquals(0, fontFormatting.getEscapementType());
|
||||||
fontFormatting.setFontWieghtModified(false);
|
assertEquals(-1, fontFormatting.getFontColorIndex());
|
||||||
assertFalse(fontFormatting.isFontWeightModified());
|
assertEquals(-1, fontFormatting.getFontHeight());
|
||||||
fontFormatting.setFontWieghtModified(true);
|
assertEquals(0, fontFormatting.getFontWeight());
|
||||||
assertTrue(fontFormatting.isFontWeightModified());
|
assertEquals(0, fontFormatting.getUnderlineType());
|
||||||
|
|
||||||
fontFormatting.setFontCancellationModified(false);
|
fontFormatting.setBold(true);
|
||||||
assertFalse(fontFormatting.isFontCancellationModified());
|
assertTrue(fontFormatting.isBold());
|
||||||
fontFormatting.setFontCancellationModified(true);
|
fontFormatting.setBold(false);
|
||||||
assertTrue(fontFormatting.isFontCancellationModified());
|
assertFalse(fontFormatting.isBold());
|
||||||
|
|
||||||
fontFormatting.setFontColorIndex((short)10);
|
fontFormatting.setEscapementType(FontFormatting.SS_SUB);
|
||||||
assertEquals(10,fontFormatting.getFontColorIndex());
|
assertEquals(FontFormatting.SS_SUB, fontFormatting.getEscapementType());
|
||||||
|
fontFormatting.setEscapementType(FontFormatting.SS_SUPER);
|
||||||
fontFormatting.setFontHeight(100);
|
assertEquals(FontFormatting.SS_SUPER, fontFormatting.getEscapementType());
|
||||||
assertEquals(100,fontFormatting.getFontHeight());
|
fontFormatting.setEscapementType(FontFormatting.SS_NONE);
|
||||||
|
assertEquals(FontFormatting.SS_NONE, fontFormatting.getEscapementType());
|
||||||
fontFormatting.setFontOutlineModified(false);
|
|
||||||
assertFalse(fontFormatting.isFontOutlineModified());
|
fontFormatting.setEscapementTypeModified(false);
|
||||||
fontFormatting.setFontOutlineModified(true);
|
assertFalse(fontFormatting.isEscapementTypeModified());
|
||||||
assertTrue(fontFormatting.isFontOutlineModified());
|
fontFormatting.setEscapementTypeModified(true);
|
||||||
|
assertTrue(fontFormatting.isEscapementTypeModified());
|
||||||
fontFormatting.setFontShadowModified(false);
|
|
||||||
assertFalse(fontFormatting.isFontShadowModified());
|
fontFormatting.setFontWieghtModified(false);
|
||||||
fontFormatting.setFontShadowModified(true);
|
assertFalse(fontFormatting.isFontWeightModified());
|
||||||
assertTrue(fontFormatting.isFontShadowModified());
|
fontFormatting.setFontWieghtModified(true);
|
||||||
|
assertTrue(fontFormatting.isFontWeightModified());
|
||||||
fontFormatting.setFontStyleModified(false);
|
|
||||||
assertFalse(fontFormatting.isFontStyleModified());
|
fontFormatting.setFontCancellationModified(false);
|
||||||
fontFormatting.setFontStyleModified(true);
|
assertFalse(fontFormatting.isFontCancellationModified());
|
||||||
assertTrue(fontFormatting.isFontStyleModified());
|
fontFormatting.setFontCancellationModified(true);
|
||||||
|
assertTrue(fontFormatting.isFontCancellationModified());
|
||||||
fontFormatting.setItalic(false);
|
|
||||||
assertFalse(fontFormatting.isItalic());
|
fontFormatting.setFontColorIndex((short)10);
|
||||||
fontFormatting.setItalic(true);
|
assertEquals(10,fontFormatting.getFontColorIndex());
|
||||||
assertTrue(fontFormatting.isItalic());
|
|
||||||
|
fontFormatting.setFontHeight(100);
|
||||||
fontFormatting.setOutline(false);
|
assertEquals(100,fontFormatting.getFontHeight());
|
||||||
assertFalse(fontFormatting.isOutlineOn());
|
|
||||||
fontFormatting.setOutline(true);
|
fontFormatting.setFontOutlineModified(false);
|
||||||
assertTrue(fontFormatting.isOutlineOn());
|
assertFalse(fontFormatting.isFontOutlineModified());
|
||||||
|
fontFormatting.setFontOutlineModified(true);
|
||||||
fontFormatting.setShadow(false);
|
assertTrue(fontFormatting.isFontOutlineModified());
|
||||||
assertFalse(fontFormatting.isShadowOn());
|
|
||||||
fontFormatting.setShadow(true);
|
fontFormatting.setFontShadowModified(false);
|
||||||
assertTrue(fontFormatting.isShadowOn());
|
assertFalse(fontFormatting.isFontShadowModified());
|
||||||
|
fontFormatting.setFontShadowModified(true);
|
||||||
fontFormatting.setStrikeout(false);
|
assertTrue(fontFormatting.isFontShadowModified());
|
||||||
assertFalse(fontFormatting.isStruckout());
|
|
||||||
fontFormatting.setStrikeout(true);
|
fontFormatting.setFontStyleModified(false);
|
||||||
assertTrue(fontFormatting.isStruckout());
|
assertFalse(fontFormatting.isFontStyleModified());
|
||||||
|
fontFormatting.setFontStyleModified(true);
|
||||||
fontFormatting.setUnderlineType(FontFormatting.U_DOUBLE_ACCOUNTING);
|
assertTrue(fontFormatting.isFontStyleModified());
|
||||||
assertEquals(FontFormatting.U_DOUBLE_ACCOUNTING, fontFormatting.getUnderlineType());
|
|
||||||
|
fontFormatting.setItalic(false);
|
||||||
fontFormatting.setUnderlineTypeModified(false);
|
assertFalse(fontFormatting.isItalic());
|
||||||
assertFalse(fontFormatting.isUnderlineTypeModified());
|
fontFormatting.setItalic(true);
|
||||||
fontFormatting.setUnderlineTypeModified(true);
|
assertTrue(fontFormatting.isItalic());
|
||||||
assertTrue(fontFormatting.isUnderlineTypeModified());
|
|
||||||
}
|
fontFormatting.setOutline(false);
|
||||||
|
assertFalse(fontFormatting.isOutlineOn());
|
||||||
public void testWrite() {
|
fontFormatting.setOutline(true);
|
||||||
HSSFWorkbook workbook = new HSSFWorkbook();
|
assertTrue(fontFormatting.isOutlineOn());
|
||||||
CFRuleRecord rr = CFRuleRecord.create(workbook, ComparisonOperator.BETWEEN, "5", "10");
|
|
||||||
|
fontFormatting.setShadow(false);
|
||||||
PatternFormatting patternFormatting = new PatternFormatting();
|
assertFalse(fontFormatting.isShadowOn());
|
||||||
patternFormatting.setFillPattern(PatternFormatting.BRICKS);
|
fontFormatting.setShadow(true);
|
||||||
rr.setPatternFormatting(patternFormatting);
|
assertTrue(fontFormatting.isShadowOn());
|
||||||
|
|
||||||
byte[] data = rr.serialize();
|
fontFormatting.setStrikeout(false);
|
||||||
assertEquals(26, data.length);
|
assertFalse(fontFormatting.isStruckout());
|
||||||
assertEquals(3, LittleEndian.getShort(data, 6));
|
fontFormatting.setStrikeout(true);
|
||||||
assertEquals(3, LittleEndian.getShort(data, 8));
|
assertTrue(fontFormatting.isStruckout());
|
||||||
|
|
||||||
int flags = LittleEndian.getInt(data, 10);
|
fontFormatting.setUnderlineType(FontFormatting.U_DOUBLE_ACCOUNTING);
|
||||||
assertEquals("unused flags should be 111", 0x00380000, flags & 0x00380000);
|
assertEquals(FontFormatting.U_DOUBLE_ACCOUNTING, fontFormatting.getUnderlineType());
|
||||||
assertEquals("undocumented flags should be 0000", 0, flags & 0x03C00000); // Otherwise Excel gets unhappy
|
|
||||||
// check all remaining flag bits (some are not well understood yet)
|
fontFormatting.setUnderlineTypeModified(false);
|
||||||
assertEquals(0x203FFFFF, flags);
|
assertFalse(fontFormatting.isUnderlineTypeModified());
|
||||||
}
|
fontFormatting.setUnderlineTypeModified(true);
|
||||||
|
assertTrue(fontFormatting.isUnderlineTypeModified());
|
||||||
private static final byte[] DATA_REFN = {
|
}
|
||||||
// formula extracted from bugzilla 45234 att 22141
|
|
||||||
1, 3,
|
public void testWrite() {
|
||||||
9, // formula 1 length
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
||||||
0, 0, 0, -1, -1, 63, 32, 2, -128, 0, 0, 0, 5,
|
CFRuleRecord rr = CFRuleRecord.create(workbook, ComparisonOperator.BETWEEN, "5", "10");
|
||||||
// formula 1: "=B3=1" (formula is relative to B4)
|
|
||||||
76, -1, -1, 0, -64, // tRefN(B1)
|
PatternFormatting patternFormatting = new PatternFormatting();
|
||||||
30, 1, 0,
|
patternFormatting.setFillPattern(PatternFormatting.BRICKS);
|
||||||
11,
|
rr.setPatternFormatting(patternFormatting);
|
||||||
};
|
|
||||||
|
byte[] data = rr.serialize();
|
||||||
/**
|
assertEquals(26, data.length);
|
||||||
* tRefN and tAreaN tokens must be preserved when re-serializing conditional format formulas
|
assertEquals(3, LittleEndian.getShort(data, 6));
|
||||||
*/
|
assertEquals(3, LittleEndian.getShort(data, 8));
|
||||||
public void testReserializeRefNTokens() {
|
|
||||||
|
int flags = LittleEndian.getInt(data, 10);
|
||||||
RecordInputStream is = TestcaseRecordInputStream.create(CFRuleRecord.sid, DATA_REFN);
|
assertEquals("unused flags should be 111", 0x00380000, flags & 0x00380000);
|
||||||
CFRuleRecord rr = new CFRuleRecord(is);
|
assertEquals("undocumented flags should be 0000", 0, flags & 0x03C00000); // Otherwise Excel gets unhappy
|
||||||
Ptg[] ptgs = rr.getParsedExpression1();
|
// check all remaining flag bits (some are not well understood yet)
|
||||||
assertEquals(3, ptgs.length);
|
assertEquals(0x203FFFFF, flags);
|
||||||
if (ptgs[0] instanceof RefPtg) {
|
}
|
||||||
throw new AssertionFailedError("Identified bug 45234");
|
|
||||||
}
|
private static final byte[] DATA_REFN = {
|
||||||
assertEquals(RefNPtg.class, ptgs[0].getClass());
|
// formula extracted from bugzilla 45234 att 22141
|
||||||
RefNPtg refNPtg = (RefNPtg) ptgs[0];
|
1, 3,
|
||||||
assertTrue(refNPtg.isColRelative());
|
9, // formula 1 length
|
||||||
assertTrue(refNPtg.isRowRelative());
|
0, 0, 0, -1, -1, 63, 32, 2, -128, 0, 0, 0, 5,
|
||||||
|
// formula 1: "=B3=1" (formula is relative to B4)
|
||||||
byte[] data = rr.serialize();
|
76, -1, -1, 0, -64, // tRefN(B1)
|
||||||
|
30, 1, 0,
|
||||||
if (!compareArrays(DATA_REFN, 0, data, 4, DATA_REFN.length)) {
|
11,
|
||||||
fail("Did not re-serialize correctly");
|
};
|
||||||
}
|
|
||||||
}
|
/**
|
||||||
|
* tRefN and tAreaN tokens must be preserved when re-serializing conditional format formulas
|
||||||
private static boolean compareArrays(byte[] arrayA, int offsetA, byte[] arrayB, int offsetB, int length) {
|
*/
|
||||||
|
public void testReserializeRefNTokens() {
|
||||||
if (offsetA + length > arrayA.length) {
|
|
||||||
return false;
|
RecordInputStream is = TestcaseRecordInputStream.create(CFRuleRecord.sid, DATA_REFN);
|
||||||
}
|
CFRuleRecord rr = new CFRuleRecord(is);
|
||||||
if (offsetB + length > arrayB.length) {
|
Ptg[] ptgs = rr.getParsedExpression1();
|
||||||
return false;
|
assertEquals(3, ptgs.length);
|
||||||
}
|
if (ptgs[0] instanceof RefPtg) {
|
||||||
for (int i = 0; i < length; i++) {
|
throw new AssertionFailedError("Identified bug 45234");
|
||||||
if (arrayA[i+offsetA] != arrayB[i+offsetB]) {
|
}
|
||||||
return false;
|
assertEquals(RefNPtg.class, ptgs[0].getClass());
|
||||||
}
|
RefNPtg refNPtg = (RefNPtg) ptgs[0];
|
||||||
}
|
assertTrue(refNPtg.isColRelative());
|
||||||
return true;
|
assertTrue(refNPtg.isRowRelative());
|
||||||
}
|
|
||||||
|
byte[] data = rr.serialize();
|
||||||
public static void main(String[] ignored_args)
|
|
||||||
{
|
if (!compareArrays(DATA_REFN, 0, data, 4, DATA_REFN.length)) {
|
||||||
System.out.println("Testing org.apache.poi.hssf.record.CFRuleRecord");
|
fail("Did not re-serialize correctly");
|
||||||
junit.textui.TestRunner.run(TestCFRuleRecord.class);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean compareArrays(byte[] arrayA, int offsetA, byte[] arrayB, int offsetB, int length) {
|
||||||
|
|
||||||
|
if (offsetA + length > arrayA.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (offsetB + length > arrayB.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
if (arrayA[i+offsetA] != arrayB[i+offsetB]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] ignored_args)
|
||||||
|
{
|
||||||
|
System.out.println("Testing org.apache.poi.hssf.record.CFRuleRecord");
|
||||||
|
junit.textui.TestRunner.run(TestCFRuleRecord.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user