cfrulerecord.java

来自「EXCEL read and write」· Java 代码 · 共 594 行 · 第 1/2 页

JAVA
594
字号
		return !field.isSet(field_5_options);	}	private void setModified(boolean modified, BitField field)	{		field_5_options = field.setBoolean(field_5_options, !modified);	}		public boolean isLeftBorderModified()	{		return isModified(bordLeft);	}	public void setLeftBorderModified(boolean modified)	{		setModified(modified,bordLeft);	}		public boolean isRightBorderModified()	{		return isModified(bordRight);	}	public void setRightBorderModified(boolean modified)	{		setModified(modified,bordRight);	}		public boolean isTopBorderModified()	{		return isModified(bordTop);	}	public void setTopBorderModified(boolean modified)	{		setModified(modified,bordTop);	}		public boolean isBottomBorderModified()	{		return isModified(bordBot);	}	public void setBottomBorderModified(boolean modified)	{		setModified(modified,bordBot);	}		public boolean isTopLeftBottomRightBorderModified()	{		return isModified(bordTlBr);	}	public void setTopLeftBottomRightBorderModified(boolean modified)	{		setModified(modified,bordTlBr);	}		public boolean isBottomLeftTopRightBorderModified()	{		return isModified(bordBlTr);	}	public void setBottomLeftTopRightBorderModified(boolean modified)	{		setModified(modified,bordBlTr);	}		public boolean isPatternStyleModified()	{		return isModified(pattStyle);	}	public void setPatternStyleModified(boolean modified)	{		setModified(modified,pattStyle);	}		public boolean isPatternColorModified()	{		return isModified(pattCol);	}	public void setPatternColorModified(boolean modified)	{		setModified(modified,pattCol);	}		public boolean isPatternBackgroundColorModified()	{		return isModified(pattBgCol);	}	public void setPatternBackgroundColorModified(boolean modified)	{		setModified(modified,pattBgCol);	}		private boolean getOptionFlag(BitField field)	{		return field.isSet(field_5_options);	}	private void setOptionFlag(boolean flag, BitField field)	{		field_5_options = field.setBoolean(field_5_options, flag);	}		/**	 * get the stack of the 1st expression as a list	 *	 * @return list of tokens (casts stack to a list and returns it!)	 * this method can return null is we are unable to create Ptgs from 	 *	 existing excel file	 * callers should check for null!	 */	public Ptg[] getParsedExpression1()	{		return field_17_formula1;	}	public void setParsedExpression1(Ptg[] ptgs) {		field_17_formula1 = safeClone(ptgs);	}	private static Ptg[] safeClone(Ptg[] ptgs) {		if (ptgs == null) {			return null;		}		return (Ptg[]) ptgs.clone();	}	/**	 * get the stack of the 2nd expression as a list	 *	 * @return list of tokens (casts stack to a list and returns it!)	 * this method can return null is we are unable to create Ptgs from 	 *	 existing excel file	 * callers should check for null!	 */	public Ptg[] getParsedExpression2()	{		return field_18_formula2;	}	public void setParsedExpression2(Ptg[] ptgs) {		field_18_formula2 = safeClone(ptgs);	}	public short getSid()	{		return sid;	}	/**	 * @param ptgs may be <code>null</code>	 * @return encoded size of the formula	 */	private static int getFormulaSize(Ptg[] ptgs) {		if (ptgs == null) {			return 0;		}		return Ptg.getEncodedSize(ptgs);	}		/**	 * called by the class that is responsible for writing this sucker.	 * Subclasses should implement this so that their data is passed back in a	 * byte array.	 *	 * @param offset to begin writing at	 * @param data byte array containing instance data	 * @return number of bytes written	 */	public int serialize(int pOffset, byte [] data)	{				int formula1Len=getFormulaSize(field_17_formula1);		int formula2Len=getFormulaSize(field_18_formula2);				int offset = pOffset;		int recordsize = getRecordSize();		LittleEndian.putShort(data, 0 + offset, sid);		LittleEndian.putShort(data, 2 + offset, (short)(recordsize-4));		data[4 + offset] = field_1_condition_type;		data[5 + offset] = field_2_comparison_operator;		LittleEndian.putUShort(data, 6 + offset, formula1Len);		LittleEndian.putUShort(data, 8 + offset, formula2Len);		LittleEndian.putInt(data,  10 + offset, field_5_options);		LittleEndian.putShort(data,14 + offset, field_6_not_used);				offset += 16;				if( containsFontFormattingBlock() )		{			byte[] fontFormattingRawRecord  = fontFormatting.getRawRecord();			System.arraycopy(fontFormattingRawRecord, 0, data, offset, fontFormattingRawRecord.length);			offset += fontFormattingRawRecord.length;		}				if( containsBorderFormattingBlock())		{			offset += borderFormatting.serialize(offset, data);		}				if( containsPatternFormattingBlock() )		{			offset += patternFormatting.serialize(offset, data);		}				if (field_17_formula1 != null) {			offset += Ptg.serializePtgs(field_17_formula1, data, offset);		}		if (field_18_formula2 != null) {			offset += Ptg.serializePtgs(field_18_formula2, data, offset);		}		if(offset - pOffset != recordsize) {			throw new IllegalStateException("write mismatch (" + (offset - pOffset) + "!=" + recordsize + ")");		}		return recordsize;	}	public int getRecordSize()	{		int retval =16+					(containsFontFormattingBlock()?fontFormatting.getRawRecord().length:0)+					(containsBorderFormattingBlock()?8:0)+					(containsPatternFormattingBlock()?4:0)+					getFormulaSize(field_17_formula1)+					getFormulaSize(field_18_formula2)					;		return retval;	}	public String toString()	{		StringBuffer buffer = new StringBuffer();		buffer.append("[CFRULE]\n");		buffer.append("    OPTION FLAGS=0x"+Integer.toHexString(getOptions()));		/*		if( containsFontFormattingBlock())		{			buffer.append(fontFormatting.toString());		}		if( containsBorderFormattingBlock())		{			buffer.append(borderFormatting.toString());		}		if( containsPatternFormattingBlock())		{			buffer.append(patternFormatting.toString());		}		buffer.append("[/CFRULE]\n");*/		return buffer.toString();	}		public Object clone() {		CFRuleRecord rec = new CFRuleRecord(field_1_condition_type, field_2_comparison_operator);		rec.field_5_options = field_5_options;		rec.field_6_not_used = field_6_not_used;		if (containsFontFormattingBlock()) {			rec.fontFormatting = (FontFormatting) fontFormatting.clone();		}		if (containsBorderFormattingBlock()) {			rec.borderFormatting = (BorderFormatting) borderFormatting.clone();		}		if (containsPatternFormattingBlock()) {			rec.patternFormatting = (PatternFormatting) patternFormatting.clone();		}		if (field_17_formula1 != null) {			rec.field_17_formula1 = (Ptg[]) field_17_formula1.clone();		}		if (field_18_formula2 != null) {			rec.field_18_formula2 = (Ptg[]) field_18_formula2.clone();		}		return rec;	}	/**	 * TODO - parse conditional format formulas properly i.e. produce tRefN and tAreaN instead of tRef and tArea	 * this call will produce the wrong results if the formula contains any cell references	 * One approach might be to apply the inverse of SharedFormulaRecord.convertSharedFormulas(Stack, int, int)	 * Note - two extra parameters (rowIx & colIx) will be required. They probably come from one of the Region objects.	 * 	 * @return <code>null</code> if <tt>formula</tt> was null.	 */	private static Ptg[] parseFormula(String formula, HSSFWorkbook workbook) {		if(formula == null) {			return null;		}		return HSSFFormulaParser.parse(formula, workbook);	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?