slaubach 2002/10/09 05:41:58
Modified: src/documentation/xdocs faq.xml
src/documentation/xdocs/hssf how-to.xml
src/java/org/apache/poi/hssf/usermodel HSSFDataFormat.java
Log:
Corrected bug in HSSFDataFormat and added alias for text format. Updated
documentation dealing with data format.
Revision Changes Path
1.22 +12 -9 jakarta-poi/src/documentation/xdocs/faq.xml
Index: faq.xml
===================================================================
RCS file: /home/cvs/jakarta-poi/src/documentation/xdocs/faq.xml,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- faq.xml 8 Oct 2002 23:14:45 -0000 1.21
+++ faq.xml 9 Oct 2002 12:41:58 -0000 1.22
@@ -134,18 +134,21 @@
</faq>
<faq>
<question>
- I want to set a cell format (Data format of a cell) of a excel sheet
as###,###,###.#### or ###,###,###.0000. Is it possible using POI ?
+ I want to set a cell format (Data format of a cell) of a excel sheet as
###,###,###.#### or ###,###,###.0000. Is it possible using POI ?
</question>
<answer>
<p>
- HSSF does not yet support custom data formats, however, it should
be a
- reasonably easy facillity to add and we'll gladly accept
contributions
- in this area.
-
- These are the built in formats that it does support:
-
-
- <link
href="http://jakarta.apache.org/poi/javadocs/javasrc/org/apache/poi/hssf/usermodel/HSSFDataFormat_java.html#HSSFDataFormat">http://jakarta.apache.org/poi/javadocs/javasrc/org/apache/poi/hssf/usermodel/HSSFDataFormat_java.html#HSSFDataFormat</link>
+ Yes. You first need to get a HSSFDataFormat object from the workbook and
call getFormat with the desired format. Some examples are <link
href="hssf/quick-guide.html#DataFormats">here</link>.
+ </p>
+ </answer>
+ </faq>
+ <faq>
+ <question>
+ I want to set a cell format (Data format of a cell) of a excel sheet as
text. Is it possible using POI ?
+ </question>
+ <answer>
+ <p>
+ Yes. This is a built-in format for excel that you can get from
HSSFDataFormat object using the format string "@". Also, the string "text" will alias
this format.
</p>
</answer>
</faq>
1.14 +7 -3 jakarta-poi/src/documentation/xdocs/hssf/how-to.xml
Index: how-to.xml
===================================================================
RCS file: /home/cvs/jakarta-poi/src/documentation/xdocs/hssf/how-to.xml,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- how-to.xml 21 Jul 2002 03:03:57 -0000 1.13
+++ how-to.xml 9 Oct 2002 12:41:58 -0000 1.14
@@ -21,7 +21,8 @@
This release allows numeric and string cell values to be written to
or read from an XLS file as well as reading and writing dates. Also
in this release is row and column sizing, cell styling (bold,
- italics, borders,etc), and support for built-in data formats. New
+ italics, borders,etc), and support for both built-in and user
+ defined data formats. New
to this release is an event-based API for reading XLS files.
It differs greatly from the read/write API
and is intended for intermediate developers who need a smaller
@@ -96,6 +97,7 @@
HSSFCellStyle cs = wb.createCellStyle();
HSSFCellStyle cs2 = wb.createCellStyle();
HSSFCellStyle cs3 = wb.createCellStyle();
+HSSFDataFormat df = wb.createDataFormat();
// create 2 fonts objects
HSSFFont f = wb.createFont();
HSSFFont f2 = wb.createFont();
@@ -119,13 +121,15 @@
//set cell stlye
cs.setFont(f);
-//set the cell format see HSSFDataFromat for a full list
-cs.setDataFormat(HSSFDataFormat.getFormat("($#,##0_);[Red]($#,##0)"));
+//set the cell format
+cs.setDataFormat(df.getFormat("#,##0.0"));
//set a thin border
cs2.setBorderBottom(cs2.BORDER_THIN);
//fill w fg fill color
cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
+//set the cell format to text see HSSFDataFormat for a full list
+cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
// set the font
cs2.setFont(f2);
1.6 +27 -18
jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java
Index: HSSFDataFormat.java
===================================================================
RCS file:
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HSSFDataFormat.java 9 Oct 2002 00:05:53 -0000 1.5
+++ HSSFDataFormat.java 9 Oct 2002 12:41:58 -0000 1.6
@@ -95,23 +95,24 @@
* 0x15, "h:mm:ss"<br>
* 0x16, "m/d/yy h:mm"<br>
*<P>
- * // 0x17 - 0x24 reserved for international and undocumented<br>
- * 0x25, "(#,##0_);(#,##0)"<br>
- * 0x26, "(#,##0_);[Red](#,##0)"<br>
- * 0x27, "(#,##0.00_);(#,##0.00)"<br>
- * 0x28, "(#,##0.00_);[Red](#,##0.00)"<br>
- * 0x29, "_(*#,##0_);_(*(#,##0);_(* \"-\"_);_(@_)"<br>
- * 0x2a, "_($*#,##0_);_($*(#,##0);_($* \"-\"_);_(@_)"<br>
- * 0x2b, "_(*#,##0.00_);_(*(#,##0.00);_(*\"-\"??_);_(@_)"<br>
- * 0x2c, "_($*#,##0.00_);_($*(#,##0.00);_($*\"-\"??_);_(@_)"<br>
- * 0x2d, "mm:ss"<br>
- * 0x2e, "[h]:mm:ss"<br>
- * 0x2f, "mm:ss.0"<br>
- * 0x30, "##0.0E+0"<br>
- * 0x31, "@"<br>
- *
+ * // 0x17 - 0x24 reserved for international and undocumented
+ * 0x25, "(#,##0_);(#,##0)"<P>
+ * 0x26, "(#,##0_);[Red](#,##0)"<P>
+ * 0x27, "(#,##0.00_);(#,##0.00)"<P>
+ * 0x28, "(#,##0.00_);[Red](#,##0.00)"<P>
+ * 0x29, "_(*#,##0_);_(*(#,##0);_(* \"-\"_);_(@_)"<P>
+ * 0x2a, "_($*#,##0_);_($*(#,##0);_($* \"-\"_);_(@_)"<P>
+ * 0x2b, "_(*#,##0.00_);_(*(#,##0.00);_(*\"-\"??_);_(@_)"<P>
+ * 0x2c, "_($*#,##0.00_);_($*(#,##0.00);_($*\"-\"??_);_(@_)"<P>
+ * 0x2d, "mm:ss"<P>
+ * 0x2e, "[h]:mm:ss"<P>
+ * 0x2f, "mm:ss.0"<P>
+ * 0x30, "##0.0E+0"<P>
+ * 0x31, "@" - This is text format.<P>
+ * 0x31 "text" - Alias for "@"<P>
*
* @author Andrew C. Oliver (acoliver at apache dot org)
+ * @author Shawn M. Laubach (slaubach at apache dot org)
*/
public class HSSFDataFormat
@@ -217,20 +218,24 @@
}
/**
- * get the format index that matches the given format string
+ * get the format index that matches the given format string<p>
+ * Automatically converts "text" to excel's format string to represent text.
* @param format string matching a built in format
* @return index of format or -1 if undefined.
*/
public static short getBuiltinFormat( String format )
{
+ if (format.toUpperCase().equals("TEXT"))
+ format = "@";
+
if ( builtinFormats == null )
{
populateBuiltinFormats();
}
short retval = -1;
- for ( short k = 0; k < 0x31; k++ )
+ for (short k = 0; k <= 0x31; k++)
{
String nformat = (String) builtinFormats.get( k );
@@ -245,7 +250,7 @@
/**
* get the format index that matches the given format string.
- * Creates a new format if one is not found.
+ * Creates a new format if one is not found. Aliases text to the proper format.
* @param format string matching a built in format
* @return index of format.
*/
@@ -254,6 +259,10 @@
{
ListIterator i;
int ind;
+
+ if (format.toUpperCase().equals("TEXT"))
+ format = "@";
+
if ( !movedBuiltins )
{
i = builtinFormats.listIterator();
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>