Top Description Inners Fields Constructors Methods
org.apache.poi.ss.format

public Class CellNumberFormatter

extends CellFormatter
Class Inheritance
Imports
java.math.BigDecimal, java.text.DecimalFormat, .DecimalFormatSymbols, .FieldPosition, .NumberFormat, java.util.ArrayList, .Collections, .Formatter, .IllegalFormatException, .Iterator, .List, .ListIterator, .Locale, .Set, .TreeSet, com.zaxxer.sparsebits.SparseBitSet, org.apache.logging.log4j.LogManager, .Logger, org.apache.poi.util.LocaleUtil

This class implements printing out a value using a number format.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static class
CellNumberFormatter.Special

This class is used to mark where the special characters in the format are, as opposed to the other characters that are simply printed.

Field Summary

Modifier and TypeField and Description
private final CellNumberFormatter.Special
private final CellNumberFormatter.Special
private final DecimalFormat
private final CellNumberFormatter.Special
private final String
private final List<CellNumberFormatter.Special>
private final String
private final CellNumberFormatter.Special
private final List<CellNumberFormatter.Special>
private final List<CellNumberFormatter.Special>
private final List<CellNumberFormatter.Special>
private final boolean
private final List<CellNumberFormatter.Special>
private static final Logger
private final int
private final CellNumberFormatter.Special
private final String
private final List<CellNumberFormatter.Special>
private final String
private final double
private final boolean
private final CellFormatter
private final CellNumberFormatter.Special
private final List<CellNumberFormatter.Special>
Inherited from org.apache.poi.ss.format.CellFormatter:
formatlocale

Constructor Summary

AccessConstructor and Description
public
CellNumberFormatter(String
The format to parse.
format
)

Creates a new cell number formatter.

public
CellNumberFormatter(Locale
The locale to use.
locale
,
String
The format to parse.
format
)

Creates a new cell number formatter.

Method Summary

Modifier and TypeMethod and Description
private int
private static CellNumberStringMod
deleteMod(CellNumberFormatter.Special start, boolean startInclusive, CellNumberFormatter.Special end, boolean endInclusive)

public void
formatValue(StringBuffer
The buffer to append to.
toAppendTo
,
Object
The value to format.
valueObject
)

Implements abstract org.apache.poi.ss.format.CellFormatter.formatValue.

Format a value according the format string.

private int
private DecimalFormatSymbols
private static boolean
hasChar(char ch, List<CellNumberFormatter.Special> numSpecials)

private static boolean
hasChar(char ch, List<CellNumberFormatter.Special> numSpecials1, List<CellNumberFormatter.Special> numSpecials2)

private static boolean
private static CellNumberStringMod
private int
private static boolean
interpretIntegerCommas(StringBuffer sb, List<CellNumberFormatter.Special> specials, CellNumberFormatter.Special decimalPoint, int integerEnd, int fractionalEnd, double[] scale)

private static int
private static boolean
private static CellNumberFormatter.Special
private String
private static int
private static void
private static String
replaceLast(String text, String regex, String replacement)

private static CellNumberStringMod
replaceMod(CellNumberFormatter.Special start, boolean startInclusive, CellNumberFormatter.Special end, boolean endInclusive, char withChar)

public void
simpleValue(StringBuffer
The buffer to append to.
toAppendTo
,
Object
The value to format.
value
)

Implements abstract org.apache.poi.ss.format.CellFormatter.simpleValue.

Format a value according to the type, in the most basic way.

private static String
private List<CellNumberFormatter.Special>
specialsFor(int pos, int takeFirst)

private List<CellNumberFormatter.Special>
specialsFor(int pos)

private void
writeFraction(double value, StringBuffer result, double fractional, StringBuffer output, Set<CellNumberStringMod> mods)

private void
private void
writeInteger(StringBuffer result, StringBuffer output, List<CellNumberFormatter.Special> numSpecials, Set<CellNumberStringMod> mods, boolean showGroupingSeparator)

private void
writeScientific(double value, StringBuffer output, Set<CellNumberStringMod> mods)

private void
Inherited from org.apache.poi.ss.format.CellFormatter:
formatquotesimpleFormat

Field Detail

afterFractionalback to summary
private final CellNumberFormatter.Special afterFractional
afterIntegerback to summary
private final CellNumberFormatter.Special afterInteger
decimalFmtback to summary
private final DecimalFormat decimalFmt
decimalPointback to summary
private final CellNumberFormatter.Special decimalPoint
denominatorFmtback to summary
private final String denominatorFmt
denominatorSpecialsback to summary
private final List<CellNumberFormatter.Special> denominatorSpecials
descback to summary
private final String desc
exponentback to summary
private final CellNumberFormatter.Special exponent
exponentDigitSpecialsback to summary
private final List<CellNumberFormatter.Special> exponentDigitSpecials
exponentSpecialsback to summary
private final List<CellNumberFormatter.Special> exponentSpecials
fractionalSpecialsback to summary
private final List<CellNumberFormatter.Special> fractionalSpecials
improperFractionback to summary
private final boolean improperFraction
integerSpecialsback to summary
private final List<CellNumberFormatter.Special> integerSpecials
LOGback to summary
private static final Logger LOG
maxDenominatorback to summary
private final int maxDenominator
numeratorback to summary
private final CellNumberFormatter.Special numerator
numeratorFmtback to summary
private final String numeratorFmt
numeratorSpecialsback to summary
private final List<CellNumberFormatter.Special> numeratorSpecials
printfFmtback to summary
private final String printfFmt
scaleback to summary
private final double scale
showGroupingSeparatorback to summary
private final boolean showGroupingSeparator
SIMPLE_NUMBERback to summary
private final CellFormatter SIMPLE_NUMBER
slashback to summary
private final CellNumberFormatter.Special slash
specialsback to summary
private final List<CellNumberFormatter.Special> specials

Constructor Detail

CellNumberFormatterback to summary
public CellNumberFormatter(String format)

Creates a new cell number formatter.

Parameters
format:String

The format to parse.

CellNumberFormatterback to summary
public CellNumberFormatter(Locale locale, String format)

Creates a new cell number formatter.

Parameters
locale:Locale

The locale to use.

format:String

The format to parse.

Method Detail

calculateIntegerPartWidthback to summary
private int calculateIntegerPartWidth()
deleteModback to summary
private static CellNumberStringMod deleteMod(CellNumberFormatter.Special start, boolean startInclusive, CellNumberFormatter.Special end, boolean endInclusive)
formatValueback to summary
public void formatValue(StringBuffer toAppendTo, Object valueObject)

Implements abstract org.apache.poi.ss.format.CellFormatter.formatValue.

Doc from org.apache.poi.ss.format.CellFormatter.formatValue.

Format a value according the format string.

Note

this method must be thread safe! In particular, if it uses a Format instance that is not thread safe, i.e. DateFormat, this method must be synchronized, either on the method, if the format is a final property, or on the format instance itself.

Parameters
toAppendTo:StringBuffer

The buffer to append to.

valueObject:Object

The value to format.

Annotations
@Override
fractionalEndback to summary
private int fractionalEnd()
getDecimalFormatSymbolsback to summary
private DecimalFormatSymbols getDecimalFormatSymbols()
hasCharback to summary
private static boolean hasChar(char ch, List<CellNumberFormatter.Special> numSpecials)
hasCharback to summary
private static boolean hasChar(char ch, List<CellNumberFormatter.Special> numSpecials1, List<CellNumberFormatter.Special> numSpecials2)
hasCharback to summary
private static boolean hasChar(char ch, List<CellNumberFormatter.Special> numSpecials1, List<CellNumberFormatter.Special> numSpecials2, List<CellNumberFormatter.Special> numSpecials3)
insertModback to summary
private static CellNumberStringMod insertMod(CellNumberFormatter.Special special, CharSequence toAdd, int where)
integerEndback to summary
private int integerEnd()
interpretIntegerCommasback to summary
private static boolean interpretIntegerCommas(StringBuffer sb, List<CellNumberFormatter.Special> specials, CellNumberFormatter.Special decimalPoint, int integerEnd, int fractionalEnd, double[] scale)
interpretPrecisionback to summary
private static int interpretPrecision(CellNumberFormatter.Special decimalPoint, List<CellNumberFormatter.Special> specials)
isDigitFmtback to summary
private static boolean isDigitFmt(CellNumberFormatter.Special s)
lastSpecialback to summary
private static CellNumberFormatter.Special lastSpecial(List<CellNumberFormatter.Special> s)
localiseFormatback to summary
private String localiseFormat(String format)
maxValueback to summary
private static int maxValue(List<CellNumberFormatter.Special> s)
placeZerosback to summary
private static void placeZeros(StringBuffer sb, List<CellNumberFormatter.Special> specials)
replaceLastback to summary
private static String replaceLast(String text, String regex, String replacement)
replaceModback to summary
private static CellNumberStringMod replaceMod(CellNumberFormatter.Special start, boolean startInclusive, CellNumberFormatter.Special end, boolean endInclusive, char withChar)
simpleValueback to summary
public void simpleValue(StringBuffer toAppendTo, Object value)

Implements abstract org.apache.poi.ss.format.CellFormatter.simpleValue.

Doc from org.apache.poi.ss.format.CellFormatter.simpleValue.

Format a value according to the type, in the most basic way.

Note

this method must be thread safe! In particular, if it uses a Format instance that is not thread safe, i.e. DateFormat, this method must be synchronized, either on the method, if the format is a final property, or on the format instance itself.

For a number, this is "#" for integer values, and "#.#" for floating-point values.

Parameters
toAppendTo:StringBuffer

The buffer to append to.

value:Object

The value to format.

Annotations
@Override
singleNumberFormatback to summary
private static String singleNumberFormat(List<CellNumberFormatter.Special> numSpecials)
specialsForback to summary
private List<CellNumberFormatter.Special> specialsFor(int pos, int takeFirst)
specialsForback to summary
private List<CellNumberFormatter.Special> specialsFor(int pos)
writeFractionback to summary
private void writeFraction(double value, StringBuffer result, double fractional, StringBuffer output, Set<CellNumberStringMod> mods)
Annotations
@SuppressWarnings:unchecked
writeFractionalback to summary
private void writeFractional(StringBuffer result, StringBuffer output)
writeIntegerback to summary
private void writeInteger(StringBuffer result, StringBuffer output, List<CellNumberFormatter.Special> numSpecials, Set<CellNumberStringMod> mods, boolean showGroupingSeparator)
writeScientificback to summary
private void writeScientific(double value, StringBuffer output, Set<CellNumberStringMod> mods)
writeSingleIntegerback to summary
private void writeSingleInteger(String fmt, int num, StringBuffer output, List<CellNumberFormatter.Special> numSpecials, Set<CellNumberStringMod> mods)
org.apache.poi.ss.format back to summary

private Class CellNumberFormatter.GeneralNumberFormatter

extends CellFormatter
Class Inheritance

Field Summary

Inherited from org.apache.poi.ss.format.CellFormatter:
formatlocale

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
formatValue(StringBuffer
The buffer to append to.
toAppendTo
,
Object
The value to format.
value
)

Implements abstract org.apache.poi.ss.format.CellFormatter.formatValue.

Format a value according the format string.

public void
simpleValue(StringBuffer
The buffer to append to.
toAppendTo
,
Object
The value to format.
value
)

Implements abstract org.apache.poi.ss.format.CellFormatter.simpleValue.

Format a value according to the type, in the most basic way.

Inherited from org.apache.poi.ss.format.CellFormatter:
formatquotesimpleFormat

Constructor Detail

GeneralNumberFormatterback to summary
private GeneralNumberFormatter(Locale locale)

Method Detail

formatValueback to summary
public void formatValue(StringBuffer toAppendTo, Object value)

Implements abstract org.apache.poi.ss.format.CellFormatter.formatValue.

Doc from org.apache.poi.ss.format.CellFormatter.formatValue.

Format a value according the format string.

Note

this method must be thread safe! In particular, if it uses a Format instance that is not thread safe, i.e. DateFormat, this method must be synchronized, either on the method, if the format is a final property, or on the format instance itself.

Parameters
toAppendTo:StringBuffer

The buffer to append to.

value:Object

The value to format.

Annotations
@Override
simpleValueback to summary
public void simpleValue(StringBuffer toAppendTo, Object value)

Implements abstract org.apache.poi.ss.format.CellFormatter.simpleValue.

Doc from org.apache.poi.ss.format.CellFormatter.simpleValue.

Format a value according to the type, in the most basic way.

Note

this method must be thread safe! In particular, if it uses a Format instance that is not thread safe, i.e. DateFormat, this method must be synchronized, either on the method, if the format is a final property, or on the format instance itself.

Parameters
toAppendTo:StringBuffer

The buffer to append to.

value:Object

The value to format.

Annotations
@Override
org.apache.poi.ss.format back to summary

pack-priv Class CellNumberFormatter.Special

extends Object
Class Inheritance

This class is used to mark where the special characters in the format are, as opposed to the other characters that are simply printed.

Field Summary

Modifier and TypeField and Description
pack-priv final char
pack-priv int

Constructor Summary

AccessConstructor and Description
pack-priv
Special(char ch, int pos)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

chback to summary
pack-priv final char ch
posback to summary
pack-priv int pos

Constructor Detail

Specialback to summary
pack-priv Special(char ch, int pos)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override