HSSFDataFormatpublic class HSSFDataFormat extends Object Utility to identify builtin formats. Now can handle user defined data formats also. The following is a list of the formats as
returned by this class.
0, "General"
1, "0"
2, "0.00"
3, "#,##0"
4, "#,##0.00"
5, "($#,##0_);($#,##0)"
6, "($#,##0_);[Red]($#,##0)"
7, "($#,##0.00);($#,##0.00)"
8, "($#,##0.00_);[Red]($#,##0.00)"
9, "0%"
0xa, "0.00%"
0xb, "0.00E+00"
0xc, "# ?/?"
0xd, "# ??/??"
0xe, "m/d/yy"
0xf, "d-mmm-yy"
0x10, "d-mmm"
0x11, "mmm-yy"
0x12, "h:mm AM/PM"
0x13, "h:mm:ss AM/PM"
0x14, "h:mm"
0x15, "h:mm:ss"
0x16, "m/d/yy h:mm"
// 0x17 - 0x24 reserved for international and undocumented
0x25, "(#,##0_);(#,##0)"
0x26, "(#,##0_);[Red](#,##0)"
0x27, "(#,##0.00_);(#,##0.00)"
0x28, "(#,##0.00_);[Red](#,##0.00)"
0x29, "_(*#,##0_);_(*(#,##0);_(* \"-\"_);_(@_)"
0x2a, "_($*#,##0_);_($*(#,##0);_($* \"-\"_);_(@_)"
0x2b, "_(*#,##0.00_);_(*(#,##0.00);_(*\"-\"??_);_(@_)"
0x2c, "_($*#,##0.00_);_($*(#,##0.00);_($*\"-\"??_);_(@_)"
0x2d, "mm:ss"
0x2e, "[h]:mm:ss"
0x2f, "mm:ss.0"
0x30, "##0.0E+0"
0x31, "@" - This is text format.
0x31 "text" - Alias for "@" |
Fields Summary |
---|
private static List | builtinFormats | private Vector | formats | private org.apache.poi.hssf.model.Workbook | workbook | private boolean | movedBuiltins |
Constructors Summary |
---|
public HSSFDataFormat(org.apache.poi.hssf.model.Workbook workbook)Construncts a new data formatter. It takes a workbook to have
access to the workbooks format records. // Flag to see if need to
// check the built in list
// or if the regular list
// has all entries.
this.workbook = workbook;
Iterator i = workbook.getFormats().iterator();
while ( i.hasNext() )
{
FormatRecord r = (FormatRecord) i.next();
if ( formats.size() < r.getIndexCode() + 1 )
{
formats.setSize( r.getIndexCode() + 1 );
}
formats.set( r.getIndexCode(), r.getFormatString() );
}
|
Methods Summary |
---|
private static synchronized java.util.List | createBuiltinFormats()
List builtinFormats = new Vector();
builtinFormats.add( 0, "General" );
builtinFormats.add( 1, "0" );
builtinFormats.add( 2, "0.00" );
builtinFormats.add( 3, "#,##0" );
builtinFormats.add( 4, "#,##0.00" );
builtinFormats.add( 5, "($#,##0_);($#,##0)" );
builtinFormats.add( 6, "($#,##0_);[Red]($#,##0)" );
builtinFormats.add( 7, "($#,##0.00);($#,##0.00)" );
builtinFormats.add( 8, "($#,##0.00_);[Red]($#,##0.00)" );
builtinFormats.add( 9, "0%" );
builtinFormats.add( 0xa, "0.00%" );
builtinFormats.add( 0xb, "0.00E+00" );
builtinFormats.add( 0xc, "# ?/?" );
builtinFormats.add( 0xd, "# ??/??" );
builtinFormats.add( 0xe, "m/d/yy" );
builtinFormats.add( 0xf, "d-mmm-yy" );
builtinFormats.add( 0x10, "d-mmm" );
builtinFormats.add( 0x11, "mmm-yy" );
builtinFormats.add( 0x12, "h:mm AM/PM" );
builtinFormats.add( 0x13, "h:mm:ss AM/PM" );
builtinFormats.add( 0x14, "h:mm" );
builtinFormats.add( 0x15, "h:mm:ss" );
builtinFormats.add( 0x16, "m/d/yy h:mm" );
// 0x17 - 0x24 reserved for international and undocumented
builtinFormats.add( 0x17, "0x17" );
builtinFormats.add( 0x18, "0x18" );
builtinFormats.add( 0x19, "0x19" );
builtinFormats.add( 0x1a, "0x1a" );
builtinFormats.add( 0x1b, "0x1b" );
builtinFormats.add( 0x1c, "0x1c" );
builtinFormats.add( 0x1d, "0x1d" );
builtinFormats.add( 0x1e, "0x1e" );
builtinFormats.add( 0x1f, "0x1f" );
builtinFormats.add( 0x20, "0x20" );
builtinFormats.add( 0x21, "0x21" );
builtinFormats.add( 0x22, "0x22" );
builtinFormats.add( 0x23, "0x23" );
builtinFormats.add( 0x24, "0x24" );
// 0x17 - 0x24 reserved for international and undocumented
builtinFormats.add( 0x25, "(#,##0_);(#,##0)" );
builtinFormats.add( 0x26, "(#,##0_);[Red](#,##0)" );
builtinFormats.add( 0x27, "(#,##0.00_);(#,##0.00)" );
builtinFormats.add( 0x28, "(#,##0.00_);[Red](#,##0.00)" );
builtinFormats.add( 0x29, "_(*#,##0_);_(*(#,##0);_(* \"-\"_);_(@_)" );
builtinFormats.add( 0x2a, "_($*#,##0_);_($*(#,##0);_($* \"-\"_);_(@_)" );
builtinFormats.add( 0x2b, "_(*#,##0.00_);_(*(#,##0.00);_(*\"-\"??_);_(@_)" );
builtinFormats.add( 0x2c,
"_($*#,##0.00_);_($*(#,##0.00);_($*\"-\"??_);_(@_)" );
builtinFormats.add( 0x2d, "mm:ss" );
builtinFormats.add( 0x2e, "[h]:mm:ss" );
builtinFormats.add( 0x2f, "mm:ss.0" );
builtinFormats.add( 0x30, "##0.0E+0" );
builtinFormats.add( 0x31, "@" );
return builtinFormats;
| public static short | getBuiltinFormat(java.lang.String format)get the format index that matches the given format string
Automatically converts "text" to excel's format string to represent text.
if (format.toUpperCase().equals("TEXT"))
format = "@";
short retval = -1;
for (short k = 0; k <= 0x31; k++)
{
String nformat = (String) builtinFormats.get( k );
if ( ( nformat != null ) && nformat.equals( format ) )
{
retval = k;
break;
}
}
return retval;
| public static java.lang.String | getBuiltinFormat(short index)get the format string that matches the given format index
return (String) builtinFormats.get( index );
| public static java.util.List | getBuiltinFormats()
return builtinFormats;
| public short | getFormat(java.lang.String format)get the format index that matches the given format string.
Creates a new format if one is not found. Aliases text to the proper format.
ListIterator i;
int ind;
if (format.toUpperCase().equals("TEXT"))
format = "@";
if ( !movedBuiltins )
{
i = builtinFormats.listIterator();
while ( i.hasNext() )
{
ind = i.nextIndex();
if ( formats.size() < ind + 1 )
{
formats.setSize( ind + 1 );
}
formats.set( ind, i.next() );
}
movedBuiltins = true;
}
i = formats.listIterator();
while ( i.hasNext() )
{
ind = i.nextIndex();
if ( format.equals( i.next() ) )
return (short) ind;
}
ind = workbook.getFormat( format, true );
if ( formats.size() <= ind )
formats.setSize( ind + 1 );
formats.set( ind, format );
return (short) ind;
| public java.lang.String | getFormat(short index)get the format string that matches the given format index
if ( movedBuiltins )
return (String) formats.get( index );
else
return (String) ( builtinFormats.size() > index
&& builtinFormats.get( index ) != null
? builtinFormats.get( index ) : formats.get( index ) );
| public static int | getNumberOfBuiltinBuiltinFormats()get the number of builtin and reserved builtinFormats
return builtinFormats.size();
|
|