Patch 45577 - Added implementations for Excel functions NOW and TODAY, added property getters to HSSFConditionalFormattingRule

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@683901 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-08-08 08:05:07 +00:00
parent 3262629faa
commit 7a0994abca
5 changed files with 114 additions and 63 deletions

View File

@ -37,7 +37,8 @@
<!-- Don't forget to update status.xml too! --> <!-- Don't forget to update status.xml too! -->
<release version="3.1.1-alpha1" date="2008-??-??"> <release version="3.1.1-alpha1" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="add">45582 - Fix for workbook streams with extra bytes trailing the EOFRecord</action> <action dev="POI-DEVELOPERS" type="add">45577 - Added implementations for Excel functions NOW and TODAY</action>
<action dev="POI-DEVELOPERS" type="fix">45582 - Fix for workbook streams with extra bytes trailing the EOFRecord</action>
<action dev="POI-DEVELOPERS" type="add">45537 - Include headers and footers (of slides and notes) in the extracted text from HSLF</action> <action dev="POI-DEVELOPERS" type="add">45537 - Include headers and footers (of slides and notes) in the extracted text from HSLF</action>
<action dev="POI-DEVELOPERS" type="fix">45472 - Fixed incorrect default row height in OpenOffice 2.3</action> <action dev="POI-DEVELOPERS" type="fix">45472 - Fixed incorrect default row height in OpenOffice 2.3</action>
<action dev="POI-DEVELOPERS" type="fix">44692 - HSSFPicture.resize() stretched image when there was a text next to it</action> <action dev="POI-DEVELOPERS" type="fix">44692 - HSSFPicture.resize() stretched image when there was a text next to it</action>

View File

@ -34,7 +34,8 @@
<!-- Don't forget to update changes.xml too! --> <!-- Don't forget to update changes.xml too! -->
<changes> <changes>
<release version="3.1.1-alpha1" date="2008-??-??"> <release version="3.1.1-alpha1" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="add">45582 - Fix for workbook streams with extra bytes trailing the EOFRecord</action> <action dev="POI-DEVELOPERS" type="add">45577 - Added implementations for Excel functions NOW and TODAY</action>
<action dev="POI-DEVELOPERS" type="fix">45582 - Fix for workbook streams with extra bytes trailing the EOFRecord</action>
<action dev="POI-DEVELOPERS" type="add">45537 - Include headers and footers (of slides and notes) in the extracted text from HSLF</action> <action dev="POI-DEVELOPERS" type="add">45537 - Include headers and footers (of slides and notes) in the extracted text from HSLF</action>
<action dev="POI-DEVELOPERS" type="fix">45472 - Fixed incorrect default row height in OpenOffice 2.3</action> <action dev="POI-DEVELOPERS" type="fix">45472 - Fixed incorrect default row height in OpenOffice 2.3</action>
<action dev="POI-DEVELOPERS" type="fix">44692 - HSSFPicture.resize() stretched image when there was a text next to it</action> <action dev="POI-DEVELOPERS" type="fix">44692 - HSSFPicture.resize() stretched image when there was a text next to it</action>

View File

@ -1,25 +1,40 @@
/* /* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
* the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and See the License for the specific language governing permissions and
* limitations under the License. limitations under the License.
*/ ==================================================================== */
/*
* Created on May 15, 2005
*
*/
package org.apache.poi.hssf.record.formula.functions; package org.apache.poi.hssf.record.formula.functions;
public class Now extends NotImplementedFunction { import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
/**
* Implementation of Excel NOW() Function
*
* @author Frank Taffelt
*/
public final class Now implements Function {
public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) {
if (evals.length > 0) {
return ErrorEval.VALUE_INVALID;
}
java.util.Date now = new java.util.Date(System.currentTimeMillis());
return new NumberEval(HSSFDateUtil.getExcelDate(now));
}
} }

View File

@ -1,25 +1,46 @@
/* /* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0 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 not use this file except in compliance with
* the License. You may obtain a copy of the License at the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and See the License for the specific language governing permissions and
* limitations under the License. limitations under the License.
*/ ==================================================================== */
/*
* Created on May 15, 2005
*
*/
package org.apache.poi.hssf.record.formula.functions; package org.apache.poi.hssf.record.formula.functions;
public class Today extends NotImplementedFunction { import java.util.Calendar;
import java.util.GregorianCalendar;
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
/**
* Implementation of Excel TODAY() Function<br/>
*
* @author Frank Taffelt
*/
public class Today implements Function {
public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) {
if (evals.length > 0) {
return ErrorEval.VALUE_INVALID;
}
Calendar now = new GregorianCalendar();
now.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE),0,0,0);
now.set(Calendar.MILLISECOND, 0);
return new NumberEval(HSSFDateUtil.getExcelDate(now.getTime()));
}
} }

View File

@ -26,17 +26,16 @@ import org.apache.poi.hssf.record.cf.PatternFormatting;
import org.apache.poi.hssf.record.formula.Ptg; import org.apache.poi.hssf.record.formula.Ptg;
/** /**
* *
* High level representation of Conditional Formatting Rule. * High level representation of Conditional Formatting Rule.
* It allows to specify formula based conditions for the Conditional Formatting * It allows to specify formula based conditions for the Conditional Formatting
* and the formatting settings such as font, border and pattern. * and the formatting settings such as font, border and pattern.
* *
* @author Dmitriy Kumshayev * @author Dmitriy Kumshayev
*/ */
public final class HSSFConditionalFormattingRule public final class HSSFConditionalFormattingRule
{ {
private static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS; private static final byte CELL_COMPARISON = CFRuleRecord.CONDITION_TYPE_CELL_VALUE_IS;
private final CFRuleRecord cfRuleRecord; private final CFRuleRecord cfRuleRecord;
private final HSSFWorkbook workbook; private final HSSFWorkbook workbook;
@ -50,11 +49,11 @@ public final class HSSFConditionalFormattingRule
{ {
return cfRuleRecord; return cfRuleRecord;
} }
private HSSFFontFormatting getFontFormatting(boolean create) private HSSFFontFormatting getFontFormatting(boolean create)
{ {
FontFormatting fontFormatting = cfRuleRecord.getFontFormatting(); FontFormatting fontFormatting = cfRuleRecord.getFontFormatting();
if ( fontFormatting != null) if ( fontFormatting != null)
{ {
cfRuleRecord.setFontFormatting(fontFormatting); cfRuleRecord.setFontFormatting(fontFormatting);
return new HSSFFontFormatting(cfRuleRecord); return new HSSFFontFormatting(cfRuleRecord);
@ -70,7 +69,7 @@ public final class HSSFConditionalFormattingRule
return null; return null;
} }
} }
/** /**
* @return - font formatting object if defined, <code>null</code> otherwise * @return - font formatting object if defined, <code>null</code> otherwise
*/ */
@ -79,19 +78,19 @@ public final class HSSFConditionalFormattingRule
return getFontFormatting(false); return getFontFormatting(false);
} }
/** /**
* create a new font formatting structure if it does not exist, * create a new font formatting structure if it does not exist,
* otherwise just return existing object. * otherwise just return existing object.
* @return - font formatting object, never returns <code>null</code>. * @return - font formatting object, never returns <code>null</code>.
*/ */
public HSSFFontFormatting createFontFormatting() public HSSFFontFormatting createFontFormatting()
{ {
return getFontFormatting(true); return getFontFormatting(true);
} }
private HSSFBorderFormatting getBorderFormatting(boolean create) private HSSFBorderFormatting getBorderFormatting(boolean create)
{ {
BorderFormatting borderFormatting = cfRuleRecord.getBorderFormatting(); BorderFormatting borderFormatting = cfRuleRecord.getBorderFormatting();
if ( borderFormatting != null) if ( borderFormatting != null)
{ {
cfRuleRecord.setBorderFormatting(borderFormatting); cfRuleRecord.setBorderFormatting(borderFormatting);
return new HSSFBorderFormatting(cfRuleRecord); return new HSSFBorderFormatting(cfRuleRecord);
@ -115,19 +114,19 @@ public final class HSSFConditionalFormattingRule
return getBorderFormatting(false); return getBorderFormatting(false);
} }
/** /**
* create a new border formatting structure if it does not exist, * create a new border formatting structure if it does not exist,
* otherwise just return existing object. * otherwise just return existing object.
* @return - border formatting object, never returns <code>null</code>. * @return - border formatting object, never returns <code>null</code>.
*/ */
public HSSFBorderFormatting createBorderFormatting() public HSSFBorderFormatting createBorderFormatting()
{ {
return getBorderFormatting(true); return getBorderFormatting(true);
} }
private HSSFPatternFormatting getPatternFormatting(boolean create) private HSSFPatternFormatting getPatternFormatting(boolean create)
{ {
PatternFormatting patternFormatting = cfRuleRecord.getPatternFormatting(); PatternFormatting patternFormatting = cfRuleRecord.getPatternFormatting();
if ( patternFormatting != null) if ( patternFormatting != null)
{ {
cfRuleRecord.setPatternFormatting(patternFormatting); cfRuleRecord.setPatternFormatting(patternFormatting);
return new HSSFPatternFormatting(cfRuleRecord); return new HSSFPatternFormatting(cfRuleRecord);
@ -143,7 +142,7 @@ public final class HSSFConditionalFormattingRule
return null; return null;
} }
} }
/** /**
* @return - pattern formatting object if defined, <code>null</code> otherwise * @return - pattern formatting object if defined, <code>null</code> otherwise
*/ */
@ -152,15 +151,29 @@ public final class HSSFConditionalFormattingRule
return getPatternFormatting(false); return getPatternFormatting(false);
} }
/** /**
* create a new pattern formatting structure if it does not exist, * create a new pattern formatting structure if it does not exist,
* otherwise just return existing object. * otherwise just return existing object.
* @return - pattern formatting object, never returns <code>null</code>. * @return - pattern formatting object, never returns <code>null</code>.
*/ */
public HSSFPatternFormatting createPatternFormatting() public HSSFPatternFormatting createPatternFormatting()
{ {
return getPatternFormatting(true); return getPatternFormatting(true);
} }
/**
* @return - the conditiontype for the cfrule
*/
public byte getConditionType() {
return cfRuleRecord.getConditionType();
}
/**
* @return - the comparisionoperatation for the cfrule
*/
public byte getComparisonOperation() {
return cfRuleRecord.getComparisonOperation();
}
public String getFormula1() public String getFormula1()
{ {
return toFormulaString(cfRuleRecord.getParsedExpression1()); return toFormulaString(cfRuleRecord.getParsedExpression1());