Class OpenXmlXlsDataProvider
- Namespace
- combit.Reporting.DataProviders
- Assembly
- combit.ListLabel31.CrossPlatform.OpenXmlXlsDataProvider.dll
Provides a data provider for reading data from .xlsx Excel files using the Open XML SDK.
[Serializable]
public sealed class OpenXmlXlsDataProvider : IDataProvider, IDisposable, ISerializable, IFileList
- Inheritance
-
OpenXmlXlsDataProvider
- Implements
- Inherited Members
Examples
The following example demonstrates how to use the OpenXmlXlsDataProvider to export a report to PDF:
// Create an OpenXmlXlsDataProvider with the Excel file path.
// The first parameter is the file path, the second indicates if the first row contains column names.
OpenXmlXlsDataProvider provider = new OpenXmlXlsDataProvider(
@"C:\Data\sales_data.xlsx",
firstRowContainsColumnNames: true);
// Optional: Enable column type detection from first data row instead of Excel formatting.
// provider.DetectColumnTypesFromFirstDataRow = true;
// Create a ListLabel reporting engine instance and assign the provider as the data source.
using ListLabel listLabel = new ListLabel();
listLabel.DataSource = provider;
// Configure export settings to generate a PDF.
ExportConfiguration exportConfiguration = new ExportConfiguration(LlExportTarget.Pdf, exportFilePath, projectFilePath);
exportConfiguration.ShowResult = true;
// Export the report to PDF.
listLabel.Export(exportConfiguration);
Remarks
The OpenXmlXlsDataProvider class implements IDataProvider to enable binding List & Label
to Excel workbook data. Each worksheet in the Excel file becomes a table in the provider. The provider supports automatic
detection of column types based on cell formatting or the first data row, and can optionally use the first row as column
names. This provider requires the DocumentFormat.OpenXml NuGet package and only supports modern .xlsx files;
older .xls format files are not supported. The provider also supports parameter binding for dynamic file paths.
Constructors
OpenXmlXlsDataProvider(string, bool)
Initializes a new instance of the OpenXmlXlsDataProvider class.
public OpenXmlXlsDataProvider(string fileName, bool firstRowContainsColumnNames)
Parameters
fileNamestringThe file to open for reading.
firstRowContainsColumnNamesboolIndicates, 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
fileNamestringThe file to open for reading.
firstRowContainsColumnNamesboolIndicates, if the first row in the file should be used as column names.
detectColumnTypesFromFirstDataRowboolIndicates, 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
fileNamestringThe file to open for reading.
firstRowContainsColumnNamesboolIndicates, if the first row in the file should be used as column names.
detectColumnTypesFromFirstDataRowboolIndicates, if the column types should be detected from the first data row instead of the formatting sheet.
sheetNamesReadOnlyCollection<string>A collection of the sheets that should be added. If
nullall 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
fileNamestringThe file to open for reading.
firstRowContainsColumnNamesboolIndicates, if the first row in the file should be used as column names.
detectColumnTypesFromFirstDataRowboolIndicates, if the column types should be detected from the first data row instead of the formatting sheet.
sheetNamesReadOnlyCollection<string>A collection of the sheets that should be added. If
nullall sheets will be added.provideFileCallbackFunc<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
FileName
Gets or sets the file name.
public string FileName { get; set; }
Property Value
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
infoSerializationInfoThe SerializationInfo to populate with data.
contextStreamingContextThe 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
fileListReadOnlyCollection<string>A read-only collection of file names to set.