[]
        
(Showing Draft Content)

DataImportOptions

Class DataImportOptions

java.lang.Object
com.grapecity.documents.excel.DataImportOptions

public class DataImportOptions extends Object
Represents options that control how data is imported into a range.

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);
 
  • Constructor Details

    • DataImportOptions

      public DataImportOptions()
  • Method Details

    • getColumnsSelector

      public Function<Object,Object> getColumnsSelector()
      Gets columns selector. It selects columns to import. The default behavior is to auto-generate all columns.
      Returns:
      The Function accepts the Iterable, array or ResultSet to select columns.
      • Returns int[] (IntArray in Kotlin) to select columns by indexes for the specified ResultSet.
      • Returns String[] to select columns by names for the specified ResultSet, dictionary or custom object.
      • Returns property getter array 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.
      • Returns named property getter array 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();
       
    • setColumnsSelector

      public void setColumnsSelector(Function<Object,Object> value)
      Sets the columns selector.

      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);
       
      Parameters:
      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.
    • getInsufficientSpaceHandling

      public InsufficientSpaceHandling getInsufficientSpaceHandling()
      Gets how insufficient space is handled when importing data.

      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();
       
      Returns:
      The insufficient-space handling mode used during data import.
    • setInsufficientSpaceHandling

      public void setInsufficientSpaceHandling(InsufficientSpaceHandling value)
      Sets how insufficient space is handled when importing data.

      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);
       
      Parameters:
      value - The insufficient-space handling mode to use during data import. The default value is InsufficientSpaceHandling.Overwrite.
    • getIncludeColumnsHeader

      public boolean getIncludeColumnsHeader()
      Gets whether column headers are included as the first row when importing data.

      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();
       
      Returns:
      true if column headers are included as the first row when importing data; false otherwise. The default value is true.
    • setIncludeColumnsHeader

      public void setIncludeColumnsHeader(boolean value)
      Sets whether column headers are included as the first row when importing data.

      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);
       
      Parameters:
      value - true if column headers are included as the first row when importing data; false otherwise. The default value is true.
    • getItemTypeProvider

      public Function<Object,Class<?>> getItemTypeProvider()
      Gets the item type provider.

      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();
       
      Returns:
      The Function that accepts the Iterable or array used to get the item type and returns the item Class. Returns null if a custom item type provider has not been set.
    • setItemTypeProvider

      public void setItemTypeProvider(Function<Object,Class<?>> value)
      Sets the item type provider.

      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);
       
      Parameters:
      value - The Function that accepts the Iterable or array used to get the item type and returns the item Class. Set null to restore the default item type resolution behavior.