Bug 7119 - [PATCH] org.apache.poi.hssf.usermodel.HSSFCell#setCellValue(Calendar value)
Summary: [PATCH] org.apache.poi.hssf.usermodel.HSSFCell#setCellValue(Calendar value)
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 1.5
Hardware: Other other
: P3 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-03-14 14:30 UTC by Lo
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lo 2002-03-14 14:30:08 UTC
--- HSSFCell.java       Wed Mar 13 17:53:21 2002
+++ HSSFCellNew.java    Wed Mar 13 17:53:02 2002
@@ -72,6 +72,7 @@
 import org.apache.poi.hssf.record.ExtendedFormatRecord;

 import java.util.Date;
+import java.util.Calendar;

 /**
  * High level representation of a cell in a row of a spreadsheet.
@@ -631,6 +632,19 @@
     public void setCellValue(Date value)
     {
         setCellValue(HSSFDateUtil.getExcelDate(value));
+    }
+
+    /**
+     * set a date value for the cell. Excel treats dates as numeric so you
will need to format the cell as
+     * a date.
+     *
+     * @param value  the date value to set this cell to.  For formulas
we'll set the
+     *        precalculated value, for numerics we'll set its value. For
othertypes we
+     *        will change the cell to a numeric cell and set its value.
+     */
+    public void setCellValue(Calendar value)
+    {
+        setCellValue(value.getTime());
     }

     /**
Comment 1 Lo 2002-03-14 15:20:36 UTC
cvs server: Diffing .
cvs server: Diffing build
cvs server: Diffing legal
cvs server: Diffing lib
cvs server: Diffing lib/core
cvs server: Diffing lib/optional
cvs server: Diffing src
cvs server: Diffing src/contrib
cvs server: Diffing src/contrib/lib
cvs server: Diffing src/contrib/src
cvs server: Diffing src/contrib/src/org
cvs server: Diffing src/contrib/src/org/apache
cvs server: Diffing src/contrib/src/org/apache/poi
cvs server: Diffing src/contrib/src/org/apache/poi/contrib
cvs server: Diffing src/contrib/src/org/apache/poi/contrib/poibrowser
cvs server: Diffing src/contrib/targets
cvs server: Diffing src/documentation
cvs server: Diffing src/documentation/images
cvs server: Diffing src/documentation/stylesheets
cvs server: Diffing src/documentation/stylesheets/printer_skin
cvs server: Diffing src/documentation/xdocs
cvs server: Diffing src/documentation/xdocs/dtd
cvs server: Diffing src/documentation/xdocs/hdf
cvs server: Diffing src/documentation/xdocs/hpsf
cvs server: Diffing src/documentation/xdocs/hssf
cvs server: Diffing src/documentation/xdocs/plan
cvs server: Diffing src/documentation/xdocs/poifs
cvs server: Diffing src/documentation/xdocs/poifs/html
cvs server: Diffing src/documentation/xdocs/resolutions
cvs server: Diffing src/documentation/xdocs/utils
cvs server: Diffing src/examples
cvs server: Diffing src/examples/src
cvs server: Diffing src/examples/src/org
cvs server: Diffing src/examples/src/org/apache
cvs server: Diffing src/examples/src/org/apache/poi
cvs server: Diffing src/examples/src/org/apache/poi/hssf
cvs server: Diffing src/examples/src/org/apache/poi/hssf/usermodel
cvs server: Diffing src/examples/src/org/apache/poi/hssf/usermodel/examples
cvs server: Diffing src/java
cvs server: Diffing src/java/org
cvs server: Diffing src/java/org/apache
cvs server: Diffing src/java/org/apache/poi
cvs server: Diffing src/java/org/apache/poi/hdf
cvs server: Diffing src/java/org/apache/poi/hpsf
cvs server: Diffing src/java/org/apache/poi/hpsf/littleendian
cvs server: Diffing src/java/org/apache/poi/hpsf/wellknown
cvs server: Diffing src/java/org/apache/poi/hssf
cvs server: Diffing src/java/org/apache/poi/hssf/dev
cvs server: Diffing src/java/org/apache/poi/hssf/eventmodel
cvs server: Diffing src/java/org/apache/poi/hssf/model
cvs server: Diffing src/java/org/apache/poi/hssf/record
cvs server: Diffing src/java/org/apache/poi/hssf/record/aggregates
cvs server: Diffing src/java/org/apache/poi/hssf/record/formula
cvs server: Diffing src/java/org/apache/poi/hssf/usermodel
Index: src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
===================================================================
RCS file: /home/cvspublic/jakarta-
poi/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java,v
retrieving revision 1.3
diff -u -r1.3 HSSFCell.java
--- src/java/org/apache/poi/hssf/usermodel/HSSFCell.java	12 Feb 2002 
02:19:12 -0000	1.3
+++ src/java/org/apache/poi/hssf/usermodel/HSSFCell.java	14 Mar 2002 
15:16:57 -0000
@@ -72,6 +72,7 @@
 import org.apache.poi.hssf.record.ExtendedFormatRecord;
 
 import java.util.Date;
+import java.util.Calendar;
 
 /**
  * High level representation of a cell in a row of a spreadsheet.
@@ -631,6 +632,19 @@
     public void setCellValue(Date value)
     {
         setCellValue(HSSFDateUtil.getExcelDate(value));
+    }
+
+    /**
+     * set a date value for the cell. Excel treats dates as numeric so you 
will need to format the cell as
+     * a date.
+     *
+     * @param value  the date value to set this cell to.  For formulas we'll 
set the
+     *        precalculated value, for numerics we'll set its value. For other 
types we
+     *        will change the cell to a numeric cell and set its value.
+     */
+    public void setCellValue(Calendar value)
+    {
+        setCellValue(value.getTime());
     }
 
     /**
cvs server: Diffing src/java/org/apache/poi/hssf/util
cvs server: Diffing src/java/org/apache/poi/poifs
cvs server: Diffing src/java/org/apache/poi/poifs/common
cvs server: Diffing src/java/org/apache/poi/poifs/dev
cvs server: Diffing src/java/org/apache/poi/poifs/eventfilesystem
cvs server: Diffing src/java/org/apache/poi/poifs/filesystem
cvs server: Diffing src/java/org/apache/poi/poifs/property
cvs server: Diffing src/java/org/apache/poi/poifs/storage
cvs server: Diffing src/java/org/apache/poi/util
cvs server: Diffing src/models
cvs server: Diffing src/records
cvs server: Diffing src/records/definitions
cvs server: Diffing src/records/styles
cvs server: Diffing src/resources
cvs server: Diffing src/resources/devtools
cvs server: Diffing src/resources/entities
cvs server: Diffing src/resources/entities/catalog-demo
cvs server: Diffing src/scratchpad
cvs server: Diffing src/scratchpad/lib
cvs server: Diffing src/scratchpad/src
cvs server: Diffing src/scratchpad/src/org
cvs server: Diffing src/scratchpad/src/org/apache
cvs server: Diffing src/scratchpad/src/org/apache/poi
cvs server: Diffing src/scratchpad/src/org/apache/poi/generator
cvs server: Diffing src/scratchpad/src/org/apache/poi/hdf
cvs server: Diffing src/scratchpad/src/org/apache/poi/hdf/extractor
cvs server: Diffing src/scratchpad/src/org/apache/poi/hdf/extractor/data
cvs server: Diffing src/scratchpad/src/org/apache/poi/hdf/extractor/util
cvs server: Diffing src/scratchpad/src/org/apache/poi/hdf/model
cvs server: Diffing src/scratchpad/src/org/apache/poi/hdf/model/hdftypes
cvs server: Diffing src/scratchpad/targets
cvs server: Diffing src/targets
cvs server: Diffing src/testcases
cvs server: Diffing src/testcases/org
cvs server: Diffing src/testcases/org/apache
cvs server: Diffing src/testcases/org/apache/poi
cvs server: Diffing src/testcases/org/apache/poi/hssf
cvs server: Diffing src/testcases/org/apache/poi/hssf/data
cvs server: Diffing src/testcases/org/apache/poi/hssf/record
cvs server: Diffing src/testcases/org/apache/poi/hssf/usermodel
Index: src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
===================================================================
RCS file: /home/cvspublic/jakarta-
poi/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java,v
retrieving revision 1.4
diff -u -r1.4 TestCellStyle.java
--- src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java	18 Feb 
2002 11:59:08 -0000	1.4
+++ src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java	14 Mar 
2002 15:17:00 -0000
@@ -135,7 +135,7 @@
     }
 
     /**
-     * Tests that is creating a file with a date works correctly.
+     * Tests that is creating a file with a date or an calendar works 
correctly.
      */
     public void testDataStyle()
             throws Exception
@@ -147,10 +147,21 @@
         HSSFSheet        s    = wb.createSheet();
         HSSFCellStyle    cs   = wb.createCellStyle();
         HSSFRow row = s.createRow((short)0);
+
+        // with Date:
         HSSFCell cell = row.createCell((short)1);
         cs.setDataFormat(HSSFDataFormat.getFormat("m/d/yy"));
         cell.setCellStyle(cs);
         cell.setCellValue(new Date());
+
+        // with Calendar:
+        cell = row.createCell((short)2);
+        cs.setDataFormat(HSSFDataFormat.getFormat("m/d/yy"));
+        cell.setCellStyle(cs);
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(new Date());
+        cell.setCellValue(cal);
+
         wb.write(out);
         out.close();
 
cvs server: Diffing src/testcases/org/apache/poi/poifs
cvs server: Diffing src/testcases/org/apache/poi/poifs/eventfilesystem
cvs server: Diffing src/testcases/org/apache/poi/poifs/filesystem
cvs server: Diffing src/testcases/org/apache/poi/poifs/property
cvs server: Diffing src/testcases/org/apache/poi/poifs/storage
cvs server: Diffing src/testcases/org/apache/poi/util
cvs server: Diffing src/testcases/org/apache/poi/util/data
cvs server: Diffing tools
cvs server: Diffing tools/ant
cvs server: Diffing tools/ant/bin
cvs server: Diffing tools/ant/lib
cvs server: Diffing tools/centipede
cvs server: Diffing tools/centipede/lib
cvs server: Diffing tools/centipede/src
cvs server: Diffing tools/centipede/src/java
cvs server: Diffing tools/centipede/src/resources
cvs server: Diffing tools/centipede/src/resources/stylesheets
cvs server: Diffing tools/centipede/targets
cvs server: Diffing tools/cocoon
cvs server: Diffing tools/cocoon/conf
cvs server: Diffing tools/cocoon/lib
cvs server: Diffing tools/lib
cvs server: Diffing tools/targets
cvs server: Diffing tools/targets/deprecated
Comment 2 Andy Oliver 2002-03-15 02:49:11 UTC
applied --  Please add yourself to the authors tags at the top of the class when
submitting patches in the future.  Thanks!