]> source.dussan.org Git - poi.git/commitdiff
Patch 45577 - Added implementations for Excel functions NOW and TODAY, added property...
authorJosh Micich <josh@apache.org>
Fri, 8 Aug 2008 08:05:07 +0000 (08:05 +0000)
committerJosh Micich <josh@apache.org>
Fri, 8 Aug 2008 08:05:07 +0000 (08:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@683901 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/formula/functions/Now.java
src/java/org/apache/poi/hssf/record/formula/functions/Today.java
src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java

index dc25332839ac81d384b69a69748fe5cc0003cd47..a18332829ab263ff3f98cd34f438090ce64aa607 100644 (file)
@@ -37,7 +37,8 @@
 
                <!-- Don't forget to update status.xml too! -->
         <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="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>
index b0230d148bf833379e8214b8afe99970186e4fbd..b0bc9bb21e4709f1e7300c5905918b96d6cc1175 100644 (file)
@@ -34,7 +34,8 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <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="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>
index 2c23a97b375b0e2e9610aeac846a51edce796b83..70930a9dcba331ab1477cbcbfc78df09f61d9e3e 100644 (file)
@@ -1,25 +1,40 @@
-/*
-* 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.
-*/
-/*
- * Created on May 15, 2005
+/* ====================================================================
+   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.record.formula.functions;
+
+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
  */
-package org.apache.poi.hssf.record.formula.functions;
+public final class Now implements Function {
 
-public class Now extends NotImplementedFunction {
+       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));
+       }
 }
index 6260d20a58e1ef32647221326721a7c75e3816c2..b70741213611bbd4f087145948f4c19d609da998 100644 (file)
@@ -1,25 +1,46 @@
-/*
-* 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.
-*/
-/*
- * Created on May 15, 2005
- *
- */
+/* ====================================================================
+   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.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()));
+       }
 }
+
index 1d4100655a686f5b9a0147116cb76f2160a7f045..10d86015aa6f8dc4d2ebbf7040abf14de043f4e4 100644 (file)
@@ -26,17 +26,16 @@ import org.apache.poi.hssf.record.cf.PatternFormatting;
 import org.apache.poi.hssf.record.formula.Ptg;
 
 /**
- * 
+ *
  * High level representation of Conditional Formatting Rule.
  * It allows to specify formula based conditions for the Conditional Formatting
  * and the formatting settings such as font, border and pattern.
- * 
+ *
  * @author Dmitriy Kumshayev
  */
-
 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 HSSFWorkbook workbook;
@@ -50,11 +49,11 @@ public final class HSSFConditionalFormattingRule
        {
                return cfRuleRecord;
        }
-       
+
        private HSSFFontFormatting getFontFormatting(boolean create)
        {
                FontFormatting fontFormatting = cfRuleRecord.getFontFormatting();
-               if ( fontFormatting != null) 
+               if ( fontFormatting != null)
                {
                        cfRuleRecord.setFontFormatting(fontFormatting);
                        return new HSSFFontFormatting(cfRuleRecord);
@@ -70,7 +69,7 @@ public final class HSSFConditionalFormattingRule
                        return null;
                }
        }
-       
+
        /**
         * @return - font formatting object  if defined,  <code>null</code> otherwise
         */
@@ -79,19 +78,19 @@ public final class HSSFConditionalFormattingRule
                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.
-        * @return - font formatting object, never returns <code>null</code>. 
+        * @return - font formatting object, never returns <code>null</code>.
         */
        public HSSFFontFormatting createFontFormatting()
        {
                return getFontFormatting(true);
        }
-       
+
        private HSSFBorderFormatting getBorderFormatting(boolean create)
        {
                BorderFormatting borderFormatting = cfRuleRecord.getBorderFormatting();
-               if ( borderFormatting != null) 
+               if ( borderFormatting != null)
                {
                        cfRuleRecord.setBorderFormatting(borderFormatting);
                        return new HSSFBorderFormatting(cfRuleRecord);
@@ -115,19 +114,19 @@ public final class HSSFConditionalFormattingRule
                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.
-        * @return - border formatting object, never returns <code>null</code>. 
+        * @return - border formatting object, never returns <code>null</code>.
         */
        public HSSFBorderFormatting createBorderFormatting()
        {
                return getBorderFormatting(true);
        }
-       
+
        private HSSFPatternFormatting getPatternFormatting(boolean create)
        {
                PatternFormatting patternFormatting = cfRuleRecord.getPatternFormatting();
-               if ( patternFormatting != null) 
+               if ( patternFormatting != null)
                {
                        cfRuleRecord.setPatternFormatting(patternFormatting);
                        return new HSSFPatternFormatting(cfRuleRecord);
@@ -143,7 +142,7 @@ public final class HSSFConditionalFormattingRule
                        return null;
                }
        }
-       
+
        /**
         * @return - pattern formatting object  if defined, <code>null</code> otherwise
         */
@@ -152,15 +151,29 @@ public final class HSSFConditionalFormattingRule
                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.
-        * @return - pattern formatting object, never returns <code>null</code>. 
+        * @return - pattern formatting object, never returns <code>null</code>.
         */
        public HSSFPatternFormatting createPatternFormatting()
        {
                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()
        {
                return toFormulaString(cfRuleRecord.getParsedExpression1());