Skip to main content

Parameter

This section introduces the parameters used in FastExcel.

Class Diagram

General Parameters

All parameters inherit from BasicParameter.

NameDefault ValueDescription
headEmptyChoose one of head or clazz. Reads the list corresponding to the file header and matches the data based on the list. It is recommended to use class.
clazzEmptyChoose one of head or clazz. Reads the class corresponding to the file header, and annotations can also be used. If neither is specified, all data will be read.
customConverterListEmptyMany converters are loaded by default. You can add unsupported fields here.
autoTrimtrueAutomatically trims the header, reads data, etc.
use1904windowingfalseIn Excel, time is stored as a double-precision floating-point number starting from 1900, but sometimes the default start date is 1904. So setting this value changes the default start date to 1904.
useScientificFormatfalseWhen converting numbers to text, whether to use scientific notation for large values.
localeEmptyDeepL Translate_ The world's most accurate translator
filedCacheLocationTHREAD_LOCALParsing the fields of the class will have a cache. Before, it was placed globally in a Map. After 3.3.0, it is placed in ThreadLocal by default, meaning that each read and write will reparse the class. You can reflectively modify the annotations of the class, and concurrent scenarios will not affect each other.
THREAD_LOCAL: Default, the cache will be cleared each time, but not the same time.
MEMORY: Placed in global memory, theoretically better performance, but cannot modify the exported object through reflection, exclusion, etc.
NONE: No caching, performance will degrade, consider using it when reading and writing at the same time, and you need to reflectively exclude, modify objects, etc.

Reading Operations

ReadBasicParameter

NameDefault ValueDescription
customReadListenerListEmptyCan register multiple listeners. When reading Excel, the listener's methods will be continuously called.
headRowNumber1The number of rows in the header of Excel, default is 1 row.

ReadWorkbook

NameDefault ValueDescription
excelTypeEmptyThe current type of Excel, supports XLS, XLSX, CSV.
inputStreamEmptyChoose between file and inputStream. Reads the file stream. If a stream is received, it is used directly. If not, it is recommended to use the file parameter. Using inputStream will help create temporary files, but in the end it is still file.
fileEmptyChoose between inputStream and file. Reads the file.
mandatoryUseInputStreamfalseForces the use of inputStream to create objects, which may degrade performance but will not create temporary files.
charsetCharset#defaultCharsetOnly useful for CSV files, specifies the encoding used when reading the file.
autoCloseStreamtrueAutomatically closes the read stream.
readCacheEmptyFor files smaller than 5MB, use memory. For files larger than 5MB, use EhCache. It is not recommended to use this parameter.
readCacheSelectorSimpleReadCacheSelectorUsed to select when to use memory to store temporary data and when to use disk to store temporary data.
ignoreEmptyRowtrueIgnore empty rows.
passwordEmptyPassword for reading the file.
xlsxSAXParserFactoryNameEmptySpecifies the name of the class used for sax reading, for example: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl.
useDefaultListenertrueBy default, ModelBuildEventListener is added to help convert to the object passed in. Setting it to false will not assist in converting objects, and custom listeners will receive a Map<Integer, CellData> object. If you still want to receive class objects, call the readListener method and add custom beforeListener, ModelBuildEventListener, and custom afterListener.
extraReadSetEmptySet of additional content to be read, which is not read by default.
readDefaultReturnSTRINGSTRING: Returns an array of Map<Integer, String>, the return value is the content you see in the Excel cell without clicking on it.
ACTUAL_DATA: Returns an array of Map<Integer, Object>, the actual data stored, will automatically convert types, Object type can be BigDecimal, Boolean, String, LocalDateTime, null, one of them.
READ_CELL_DATA: Returns an array of Map<Integer, ReadCellData<?>>, where ? type refers to ACTUAL_DATA.
customObjectSTRINGSTRING: Returns an array of Map<Integer, String>, the return value is the content you see in the Excel cell without clicking on it.
ACTUAL_DATA: Returns an array of Map<Integer, Object>, the actual data stored, will automatically convert types, Object type can be BigDecimal, Boolean, String, LocalDateTime, null, one of them.
READ_CELL_DATA: Returns an array of Map<Integer, ReadCellData<?>>, where ? type refers to ACTUAL_DATA.
numRows0Read the specified number of rows. 0 means no limit on the number of rows, i.e. read all rows.
ignoreHiddenSheettrue@since 1.3.0
Ignore hidden sheets.
csvFormatCSVFormat.DEFAULT@since 1.3.0
Set the CSVFormat object, which is only valid for csv files.

ReadSheet

NameDefault ValueDescription
sheetNo0The code of the Sheet to be read, recommended to use this to specify which Sheet to read.
sheetNameEmptyMatch the Sheet by name.
sheetHiddenfalseNormal Hidden Status
sheetVeryHiddenfalseAbsolute Hidden State
numRows0Read the specified number of rows. 0 means no limit on the number of rows, i.e. read all rows.

Writing Operations

WriteBasicParameter

NameDefault ValueDescription
customWriteHandlerListEmptyWriting handler. Can implement WorkbookWriteHandler, SheetWriteHandler, RowWriteHandler, CellWriteHandler, which will be called at different stages of writing to Excel.
relativeHeadRowIndex0Number of rows to leave blank above Excel.
needHeadtrueWhether to write the header to Excel.
useDefaultStyletrueWhether to use default styles.
automaticMergeHeadtrueAutomatically merge headers, matching the same fields above, below, left, and right in the header.
excludeColumnIndexesEmptyExclude indexes of data in the object.
excludeColumnFieldNamesEmptyExclude fields of data in the object.
includeColumnIndexesEmptyOnly export indexes of data in the object.
includeColumnFieldNamesEmptyOnly export fields of data in the object.
orderByIncludeColumnfalseWhen using the parameters includeColumnFieldNames or includeColumnIndexes, it will sort according to the order of the collection passed in.

WriteWorkbook

NameDefault ValueDescription
excelTypeEmptyThe current type of Excel, supports XLS, XLSX, CSV.
outputStreamEmptyChoose between file and outputStream. Writes the file stream.
fileEmptyChoose between outputStream and file. Writes the file.
templateInputStreamEmptyTemplate file stream.
templateFileEmptyTemplate file.
charsetCharset#defaultCharsetOnly useful for CSV files, specifies the encoding used when writing the file.
autoCloseStreamtrueAutomatically closes the write stream.
passwordEmptyPassword for reading the file.
inMemoryfalseWhether to process in memory, by default, a temporary file will be generated to save memory. Memory mode is more efficient, but prone to OOM.
writeExcelOnExceptionfalseIf an exception occurs during writing, whether to try to write the data to Excel.
withBomtrueSet the encoding prefix in the CSV file, otherwise Office software may display garbled characters.
mandatoryUseInputStreamfalseForces the use of inputStream to create objects, which may degrade performance but will not create temporary files.
csvFormatCSVFormat.DEFAULT@since 1.3.0
Set the CSVFormat object, which is only valid for csv files.

WriteSheet

NameDefault ValueDescription
sheetNo0Code of the Sheet to be written.
sheetNameEmptyName of the Sheet to be written, defaults to sheetNo.

WriteTable

NameDefault ValueDescription
tableNo0Code of the table to be written.