[]
Use this class with IRange.importData(Object,DataImportOptions) to configure behaviors such as how insufficient space is handled, whether column headers are included, which columns are imported, and how the item type is resolved for auto-generated columns.
Map<String, Object> item = new LinkedHashMap<>();
item.put("Name", "Alice");
item.put("City", "Seattle");
Map<String, Object>[] items = new Map[] {item};
DataImportOptions options = new DataImportOptions();
worksheet.getRange("A1").importData(items, options);
booleanvoidsetColumnsSelector(Function<Object,Object> value) voidsetIncludeColumnsHeader(boolean value) voidvoidsetItemTypeProvider(Function<Object,Class<?>> value) Function accepts the Iterable, array or ResultSet to select columns.int[] (IntArray in Kotlin) to select columns by indexes for the specified ResultSet.String[] to select columns by names for the specified ResultSet, dictionary or custom object.Function[] (where T is the element type of collection, R is the property type)to select columns with custom column getters. In this case, getIncludeColumnsHeader() must be false. Otherwise, an exception will be thrown. Because we don't know the column names.AbstractMap.SimpleEntry[] (where K is column name String, V is property getter Function; For each Function, T is the element type of collection, R is the property type)to select columns with custom column names and custom column getters. In this case, getIncludeColumnsHeader() should be true. Otherwise, the column names will be ignored.
DataImportOptions options = new DataImportOptions();
options.setColumnsSelector(source -> new String[] {"Name", "City"});
Function<Object, Object> selector = options.getColumnsSelector();
Selects which columns are imported when using IRange.importData(Object,DataImportOptions). If no selector is specified, all columns are generated automatically.
The selector function receives the source object passed to importData and returns the columns to import. Depending on the source type, the function can return column indexes, column names, or custom column definitions.
Map<String, Object> item = new LinkedHashMap<>();
item.put("Name", "Alice");
item.put("Age", 30);
item.put("City", "Seattle");
Map<String, Object>[] items = new Map[] {item};
DataImportOptions options = new DataImportOptions();
options.setColumnsSelector(source -> new String[] {"Name", "City"});
worksheet.getRange("A1").importData(items, options);
value - The selector function that accepts the source object supplied to IRange.importData(Object,DataImportOptions) and returns the columns to import. Return int[] to select columns by index, String[] to select columns by name, Function[] to provide custom value selectors without column names (in this case, getIncludeColumnsHeader() must be false), or AbstractMap.SimpleEntry[] to provide custom column names together with value selectors (in this case, getIncludeColumnsHeader() should be true; otherwise, the custom column names are ignored). null uses the default column generation behavior.This setting controls how the import operation behaves when the target range does not have enough cells to contain all imported data. The default value is InsufficientSpaceHandling.Overwrite.
DataImportOptions options = new DataImportOptions();
InsufficientSpaceHandling handling = options.getInsufficientSpaceHandling();
This setting controls how the import operation behaves when the target range does not have enough cells to contain all imported data. The default value is InsufficientSpaceHandling.Overwrite.
DataImportOptions options = new DataImportOptions();
options.setInsufficientSpaceHandling(InsufficientSpaceHandling.Truncate);
value - The insufficient-space handling mode to use during data import. The default value is InsufficientSpaceHandling.Overwrite.This option controls whether imported tabular data writes a header row before the data rows. The default value is true.
DataImportOptions options = new DataImportOptions();
boolean includeHeaders = options.getIncludeColumnsHeader();
true if column headers are included as the first row when importing data; false otherwise. The default value is true.This option controls whether imported tabular data writes a header row before the data rows. The default value is true.
DataImportOptions options = new DataImportOptions();
options.setIncludeColumnsHeader(false);
value - true if column headers are included as the first row when importing data; false otherwise. The default value is true.The item type provider gets the item type from the specified Iterable or array. The type is used to generate columns when importing data. If no custom provider is set, the default behavior is to try to get the item type from the array, then try to get the type from the first item.
DataImportOptions options = new DataImportOptions();
options.setItemTypeProvider(source -> Object.class);
Function<Object, Class<?>> provider = options.getItemTypeProvider();
The item type provider gets the item type from the specified Iterable or array. The type is used to generate columns when importing data. If no custom provider is set, the default behavior is to try to get the item type from the array, then try to get the type from the first item.
DataImportOptions options = new DataImportOptions();
options.setItemTypeProvider(source -> Object.class);