Package ch.rabanti.nanoxlsx4j
Class ImportOptions
java.lang.Object
ch.rabanti.nanoxlsx4j.ImportOptions
The import options define global rules to import worksheets. The options are mainly to override particular cell types
(e.g. interpretation of dates as numbers)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumColumn types to enforce during the importstatic enumGlobal conversion types to enforce during the import. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEnforcedColumn(int columnNumber, ImportOptions.ColumnType type) Adds a type enforcing rule to the passed column number (zero-based)voidaddEnforcedColumn(String columnAddress, ImportOptions.ColumnType type) Adds a type enforcing rule to the passed column addressGets the format if Date values are cast to StringsGets the Date formatter, set by the string ofsetDateFormat(String)gets the type enforcing rules during import for particular columnsintgets the row number (zero-based) where enforcing rules are started to be applied.Gets the global strategy to handle cell values.Gets the Locale instance, used to parse Duration objects from strings.Gets the format if Duration (time) values are cast to StringsGets the formatter to parse a Duration (time), set by the string ofsetTimeFormat(String)booleanGets whether date or time values in the workbook are interpreted as numbersbooleanGets whether empty cells are of the type Empty or StringbooleanGets whether phonetic characters (like ruby characters / Furigana / Zhuyin fuhao) in strings are added in brackets after the transcribed symbols.booleanGets whether invalid column dimensions (larger thanWorksheet.MAX_COLUMN_WIDTHor smaller thanWorksheet.MIN_COLUMN_WIDTH) will throw an exceptionbooleanGets whether invalid row dimensions (larger thanWorksheet.MAX_ROW_HEIGHTor smaller thanWorksheet.MIN_ROW_HEIGHT) will throw an exceptionvoidsetDateFormat(String dateFormat) Sets the format if Date values are cast to StringsvoidsetEnforceDateTimesAsNumbers(boolean enforceDateTimesAsNumbers) Sets whether date or time values in the workbook are interpreted as numbersvoidsetEnforceEmptyValuesAsString(boolean enforceEmptyValuesAsString) Sets whether empty cells are of the type Empty or StringvoidsetEnforcePhoneticCharacterImport(boolean enforcePhoneticCharacterImport) Sets whether phonetic characters (like ruby characters / Furigana / Zhuyin fuhao) in strings are added in brackets after the transcribed symbols.voidsetEnforceValidColumnDimensions(boolean enforceValidColumnDimensions) Sets whether invalid column dimensions (larger thanWorksheet.MAX_COLUMN_WIDTHor smaller thanWorksheet.MIN_COLUMN_WIDTH) will throw an exceptionvoidsetEnforceValidRowDimensions(boolean enforceValidRowDimensions) Sets whether invalid row dimensions (larger thanWorksheet.MAX_ROW_HEIGHTor smaller thanWorksheet.MIN_ROW_HEIGHT) will throw an exceptionvoidsetEnforcingStartRowNumber(int enforcingStartRowNumber) Sets the row number (zero-based) where enforcing rules are started to be applied.voidsetGlobalEnforcingType(ImportOptions.GlobalType globalEnforcingType) Sets the global strategy to handle cell values.voidsetTemporalLocale(Locale temporalLocale) Sets the Locale instance, used to parse Duration objects from strings.voidsetTimeFormat(String timeFormat) Sets the format if LocalTime values are cast to Strings.
Note that the parameter 'n' in a pattern is used to parse the number of days since 1900-01-01
-
Field Details
-
DEFAULT_DATE_FORMAT
Default format if Date values are cast to strings- See Also:
-
DEFAULT_TIME_FORMAT
Default format if time (Duration) values are cast to strings- See Also:
-
DEFAULT_LOCALE
Default locale instance (en-US) used for time parsing, if no custom locale is defined
-
-
Constructor Details
-
ImportOptions
public ImportOptions()
-
-
Method Details
-
isEnforceDateTimesAsNumbers
public boolean isEnforceDateTimesAsNumbers()Gets whether date or time values in the workbook are interpreted as numbers- Returns:
- If true, date or time values (default format number 14 or 21) will be interpreted as numeric values
globally. This option overrules possible column options, defined by
addEnforcedColumn(int, ColumnType)
-
getEnforcedColumnTypes
gets the type enforcing rules during import for particular columns- Returns:
- Map of column numbers and enforced types
-
getEnforcingStartRowNumber
public int getEnforcingStartRowNumber()gets the row number (zero-based) where enforcing rules are started to be applied. This is, for instance, to prevent enforcing in a header row- Returns:
- Row number
-
setEnforceDateTimesAsNumbers
public void setEnforceDateTimesAsNumbers(boolean enforceDateTimesAsNumbers) Sets whether date or time values in the workbook are interpreted as numbers- Parameters:
enforceDateTimesAsNumbers- If true, date or time values (default format number 14 or 21) will be interpreted as numeric values globally. This option overrules possible column options, defined byaddEnforcedColumn(int, ColumnType)
-
setEnforcingStartRowNumber
public void setEnforcingStartRowNumber(int enforcingStartRowNumber) Sets the row number (zero-based) where enforcing rules are started to be applied. This is, for instance, to prevent enforcing types in a header row. Any enforcing rule is skipped until this row number is reached- Parameters:
enforcingStartRowNumber- Row number
-
addEnforcedColumn
Adds a type enforcing rule to the passed column address- Parameters:
columnAddress- Column address (A to XFD)type- Type to be enforced on the column
-
addEnforcedColumn
Adds a type enforcing rule to the passed column number (zero-based)- Parameters:
columnNumber- Column number (0-16383)type- Type to be enforced on the column
-
isEnforcePhoneticCharacterImport
public boolean isEnforcePhoneticCharacterImport()Gets whether phonetic characters (like ruby characters / Furigana / Zhuyin fuhao) in strings are added in brackets after the transcribed symbols. By default, phonetic characters are removed from strings.- Returns:
- If true, phonetic characters will be appended, otherwise discarded
-
setEnforcePhoneticCharacterImport
public void setEnforcePhoneticCharacterImport(boolean enforcePhoneticCharacterImport) Sets whether phonetic characters (like ruby characters / Furigana / Zhuyin fuhao) in strings are added in brackets after the transcribed symbols. By default, phonetic characters are removed from strings.- API Note:
- This option is not applicable to specific rows or a start column (applied globally)
- Parameters:
enforcePhoneticCharacterImport- If true, phonetic characters will be appended, otherwise discarded
-
isEnforceEmptyValuesAsString
public boolean isEnforceEmptyValuesAsString()Gets whether empty cells are of the type Empty or String- Returns:
- If true, empty cells will be interpreted as type of string with an empty value. If false, the type will be Empty and the value null
-
setEnforceEmptyValuesAsString
public void setEnforceEmptyValuesAsString(boolean enforceEmptyValuesAsString) Sets whether empty cells are of the type Empty or String- Parameters:
enforceEmptyValuesAsString- If true, empty cells will be interpreted as type of string with an empty value. If false, the type will be Empty and the value null
-
isEnforceValidColumnDimensions
public boolean isEnforceValidColumnDimensions()Gets whether invalid column dimensions (larger thanWorksheet.MAX_COLUMN_WIDTHor smaller thanWorksheet.MIN_COLUMN_WIDTH) will throw an exception- Returns:
- If true, invalid column dimensions will trow an exception. If false, such invalid values will be ignored
and set to
Worksheet.MAX_COLUMN_WIDTHorWorksheet.MIN_COLUMN_WIDTH. Default is true
-
setEnforceValidColumnDimensions
public void setEnforceValidColumnDimensions(boolean enforceValidColumnDimensions) Sets whether invalid column dimensions (larger thanWorksheet.MAX_COLUMN_WIDTHor smaller thanWorksheet.MIN_COLUMN_WIDTH) will throw an exception- Parameters:
enforceValidColumnDimensions- If true, invalid column dimensions will trow an exception. If false, such invalid values will be ignored and set toWorksheet.MAX_COLUMN_WIDTHorWorksheet.MIN_COLUMN_WIDTH. Default is true
-
isEnforceValidRowDimensions
public boolean isEnforceValidRowDimensions()Gets whether invalid row dimensions (larger thanWorksheet.MAX_ROW_HEIGHTor smaller thanWorksheet.MIN_ROW_HEIGHT) will throw an exception- Returns:
- If true, invalid row dimensions will trow an exception. If false, such invalid values will be ignored and
set to
Worksheet.MAX_ROW_HEIGHTorWorksheet.MIN_ROW_HEIGHT. Default is true
-
setEnforceValidRowDimensions
public void setEnforceValidRowDimensions(boolean enforceValidRowDimensions) Sets whether invalid row dimensions (larger thanWorksheet.MAX_ROW_HEIGHTor smaller thanWorksheet.MIN_ROW_HEIGHT) will throw an exception- Parameters:
enforceValidRowDimensions- If true, invalid row dimensions will trow an exception. If false, such invalid values will be ignored and set toWorksheet.MAX_ROW_HEIGHTorWorksheet.MIN_ROW_HEIGHT. Default is true
-
getGlobalEnforcingType
Gets the global strategy to handle cell values. The default will not enforce any general casting, beside defined values ofsetEnforceDateTimesAsNumbers(boolean),setEnforceEmptyValuesAsString(boolean)andaddEnforcedColumn(int, ColumnType)- Returns:
- Global cast strategy on import
-
setGlobalEnforcingType
Sets the global strategy to handle cell values. The default will not enforce any casting, beside defined values ofsetEnforceDateTimesAsNumbers(boolean),setEnforceEmptyValuesAsString(boolean)andaddEnforcedColumn(int, ColumnType)- Parameters:
globalEnforcingType- Global cast strategy on import
-
getDateFormat
Gets the format if Date values are cast to Strings- Returns:
- String format pattern
-
setDateFormat
Sets the format if Date values are cast to Strings- Parameters:
dateFormat- String format pattern
-
getTemporalLocale
Gets the Locale instance, used to parse Duration objects from strings. If null, parsing will be tried with 'best effort'.- Returns:
- Locale instance used for parsing
-
setTemporalLocale
Sets the Locale instance, used to parse Duration objects from strings. If null, parsing will be tried with 'best effort'.- Parameters:
temporalLocale- Locale instance used for parsing
-
getDateFormatter
Gets the Date formatter, set by the string ofsetDateFormat(String)- Returns:
- SimpleDateFormat instance
-
getTimeFormat
Gets the format if Duration (time) values are cast to Strings- Returns:
- String format pattern
-
setTimeFormat
Sets the format if LocalTime values are cast to Strings.
Note that the parameter 'n' in a pattern is used to parse the number of days since 1900-01-01- API Note:
- Supported formatting tokens are all time-related patterns like 'HH', 'mm', 'ss'. To represent the number of days, the pattern 'n' is used. This deviates from the actual definition of 'n' which would be nanoseconds of the second.
- Parameters:
timeFormat- String format pattern
-
getTimeFormatter
Gets the formatter to parse a Duration (time), set by the string ofsetTimeFormat(String)- Returns:
- DateTimeFormatter instance
-