Skip to content
Snippets Groups Projects
Select Git revision
  • main default
  • 2025Q1
  • 2024Q1
  • 2024Q4
  • 2024Q3
  • 2024Q2
  • 2023Q4
  • 2023Q3
  • 2023Q2
  • 2023Q1
  • 2022Q4
  • 2022Q3
  • 2022Q2
  • 2022Q1
  • 2021Q4
  • 2021Q3
  • 2021Q2
  • 2021Q1
  • 2020Q4
  • 2020Q3
  • release/13.5.0
  • 13.3-eol
  • release/14.2.0
  • 14.0-eol
  • release/13.4.0
  • release/14.1.0
  • release/13.3.0
  • 12-eol
  • 12.4-eol
  • release/14.0.0
  • 13.1-eol-q
  • 13.1-eol
  • 12.3-last
  • 12.3-eol
  • release/13.2.0
  • release/12.4.0
  • release/13.1.0
  • release/12.3.0
  • 11-eol
  • release/13.0.0
40 results

dinotrace

  • Clone with SSH
  • Clone with HTTPS
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.

    FlexPorter

    The FlexPorter is an excel data importing library capable of auto-detecting header rows and object types. It grants the ability to read data from excel files in a simple and lightweight manner.

    The library is available on nuget.org (https://api.nuget.org/v3/index.json) under the name FlexPorter.

    FlexPorter is capable of scanning excel files in order to find a row of column headers with data rows underneath it:

    alt text

    alt text

    The column headers correspond to properties marked with the ExcelImportField attribute in a C# class that implements the IExcelImportRecord interface:

    alt text

    In addition to the auto-detection of the header row location, XL porter supports the auto-detection from multiple candidate object types.

    Usage

    After defining a class with marked ExcelImportField attributes and instantiating an ExcelImporter, importing an excel file using auto-detection of column header row location is a simple matter of calling the HandleImport function:

    alt text

    alt text

    This function can be called with or without a generic type argument. If no type argument is provided, the type is auto-detected.

    Any classes that extend from IExcelImportRecord that are defined in the project that the ExcelImporter is instantiated in are candidates for auto-detection.

    Whichever class has the most ExcelImportFields matching the column headers in the sheet is used for the import.

    The candidate classes are found using Reflection in the constructor of ExcelImporter, so there is no need to supply a list to the ExcelImporter separately:

    alt text

    alt text

    Specialized import functions

    It is possible to supply specialized import functions for types that have non-standard import mechanisms. This is done as follows:

    alt text

    The import mechanism can then be user-defined by writing a method with the following signature:

    alt text

    Use the GetPropertyByImportField method to find the PropertyInfo that corresponds to anExcelImportField attribute on your import class:

    alt text

    This method returns null if no matching property was found.

    The headerRowInfo argument will be filled in when type auto-detection is used. Otherwise, the argument is null and you can fill it using your own header detection algorithm.

    To use the standard auto-detection algorithm, use the GetBestHeaderRowInfo function.

    The HeaderRowInfo class contains the type of the object, index of the header row, the string values of the entire row (including blanks or non header values) and a list of the found headers (excluding other values):

    alt text

    Data tranformer

    It is possible to specify a method that is called on all read values, that transforms the value before it is written to the object's properties. This is done as follows:

    alt text

    alt text

    ExcelImport.DefaultTransformer can be used to apply the default tranformation function, which is currently defined as follows:

    alt text