Table of Contents

Class OpenXmlXlsDataProvider

Namespace
combit.Reporting.DataProviders
Assembly
combit.ListLabel31.CrossPlatform.OpenXmlXlsDataProvider.dll

Provider for reading data from .xlsx files using the Open XML SDK. This provider can be used to bind List & Label to Excel data and supports automatic detection of field types. Older .xls type files are not supported.

[Serializable]
public sealed class OpenXmlXlsDataProvider : IDataProvider, IDisposable, ISerializable, IFileList
Inheritance
OpenXmlXlsDataProvider
Implements
Inherited Members

Examples

The following example demonstrates how to initialize the provider and bind it to a List & Label data source:

// Initialize the provider with the file name and specify that the first row contains column names.
var provider = new OpenXmlXlsDataProvider(fileName, firstRowContainsColumnNames: true);

// Bind the provider to the List & Label data source.
LL.DataSource = provider;

Remarks

This class requires the DocumentFormat.OpenXml NuGet package to be installed.

Constructors

OpenXmlXlsDataProvider(string, bool)

Initializes a new instance of the OpenXmlXlsDataProvider class.

public OpenXmlXlsDataProvider(string fileName, bool firstRowContainsColumnNames)

Parameters

fileName string

The file to open for reading.

firstRowContainsColumnNames bool

Indicates, if the first row in the file should be used as column names.

OpenXmlXlsDataProvider(string, bool, bool)

Initializes a new instance of the OpenXmlXlsDataProvider class.

public OpenXmlXlsDataProvider(string fileName, bool firstRowContainsColumnNames, bool detectColumnTypesFromFirstDataRow)

Parameters

fileName string

The file to open for reading.

firstRowContainsColumnNames bool

Indicates, if the first row in the file should be used as column names.

detectColumnTypesFromFirstDataRow bool

Indicates, if the column types should be detected from the first data row instead of the formatting sheet.

OpenXmlXlsDataProvider(string, bool, bool, ReadOnlyCollection<string>)

Initializes a new instance of the OpenXmlXlsDataProvider class.

public OpenXmlXlsDataProvider(string fileName, bool firstRowContainsColumnNames, bool detectColumnTypesFromFirstDataRow, ReadOnlyCollection<string> sheetNames)

Parameters

fileName string

The file to open for reading.

firstRowContainsColumnNames bool

Indicates, if the first row in the file should be used as column names.

detectColumnTypesFromFirstDataRow bool

Indicates, if the column types should be detected from the first data row instead of the formatting sheet.

sheetNames ReadOnlyCollection<string>

A collection of the sheets that should be added. If null all sheets will be added.

OpenXmlXlsDataProvider(string, bool, bool, ReadOnlyCollection<string>, Func<string, string>)

Initializes a new instance of the OpenXmlXlsDataProvider class.

public OpenXmlXlsDataProvider(string fileName, bool firstRowContainsColumnNames, bool detectColumnTypesFromFirstDataRow, ReadOnlyCollection<string> sheetNames, Func<string, string> provideFileCallback)

Parameters

fileName string

The file to open for reading.

firstRowContainsColumnNames bool

Indicates, if the first row in the file should be used as column names.

detectColumnTypesFromFirstDataRow bool

Indicates, if the column types should be detected from the first data row instead of the formatting sheet.

sheetNames ReadOnlyCollection<string>

A collection of the sheets that should be added. If null all sheets will be added.

provideFileCallback Func<string, string>

This callback will be called if the FileName-Property is changed. The result is the new filelocation that should be used instead.

Properties

DetectColumnTypesFromFirstDataRow

Enabling this property will detect the datatypes of the Columns based on the first row of aata instead of the formatting sheet given by Ecxel.

public bool DetectColumnTypesFromFirstDataRow { get; set; }

Property Value

bool

FileName

Gets or sets the file name.

public string FileName { get; set; }

Property Value

string

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

~OpenXmlXlsDataProvider()

protected ~OpenXmlXlsDataProvider()

GetFileList()

Retrieves the current list of file names.

public ReadOnlyCollection<string> GetFileList()

Returns

ReadOnlyCollection<string>

A read-only collection of file names.

GetObjectData(SerializationInfo, StreamingContext)

Populates a SerializationInfo with the data needed to serialize the target object.

public void GetObjectData(SerializationInfo info, StreamingContext context)

Parameters

info SerializationInfo

The SerializationInfo to populate with data.

context StreamingContext

The destination (see StreamingContext) for this serialization.

Exceptions

SecurityException

The caller does not have the required permission.

SetFileList(ReadOnlyCollection<string>)

Sets the list of file names.

public void SetFileList(ReadOnlyCollection<string> fileList)

Parameters

fileList ReadOnlyCollection<string>

A read-only collection of file names to set.