Package io.keikai.axyra.sheets.format
Class Formats
java.lang.Object
io.keikai.axyra.sheets.format.Formats
Number and date formatting with Excel format codes, and classification of
typed input. These are the engine's formatting rules as stateless helpers;
no workbook is needed. Date serials use the 1900 date system. For the text a
cell shows in a workbook, which follows that workbook's date system, use
Cell.formattedText().
String s = Formats.format(1234.5, "#,##0.00"); // "1,234.50"
ParsedValue v = Formats.parse("50%"); // NUMBER, 0.5
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringFormats a number with an Excel format code under en-US conventions, e.g.static StringFormats a number with an Excel format code under a BCP-47 display locale.static ParsedValueClassifies user-typed cell text the way Excel does when a value is entered into a cell: numbers (including"50%","$1,234.56","1/2","1.5E3"), dates and times (as Excel serials), booleans, formulas (leading=) and plain text.
-
Method Details
-
format
Formats a number with an Excel format code under en-US conventions, e.g.format(1234.5, "#,##0.00")gives"1,234.50"andformat(45000, "yyyy-mm-dd")gives"2023-03-15". Date serials use the 1900 date system.- Parameters:
value- the number or date serialcode- the Excel format code, e.g."0.00%"- Returns:
- the formatted text
- Throws:
AxyraException- ifcodeisnull
-
format
Formats a number with an Excel format code under a BCP-47 display locale. Month and weekday names, AM/PM markers, and the decimal and thousands separators follow the locale, e.g.format(1234.56, "#,##0.00", "de-DE")gives"1.234,56". The format code itself does not change with the locale:.and,in the code always mean the decimal point and the thousands separator. Date serials use the 1900 date system.- Parameters:
value- the number or date serialcode- the Excel format code in en-US syntaxlocaleTag- a BCP-47 tag such as"de-DE";null, empty or unknown tags fall back to en-US- Returns:
- the formatted text
- Throws:
AxyraException- ifcodeisnull
-
parse
Classifies user-typed cell text the way Excel does when a value is entered into a cell: numbers (including"50%","$1,234.56","1/2","1.5E3"), dates and times (as Excel serials), booleans, formulas (leading=) and plain text. Classification uses en-US conventions and the 1900 date system. Leading and trailing spaces are ignored; whitespace-only input is TEXT with empty text. Reference: ECMA-376 Part 1 §18.17.2.3 (data types).- Parameters:
text- the typed text- Returns:
- the classified value
- Throws:
AxyraException- iftextisnull
-