MeshWeaver.DataSetReader.Excel.Utils 2.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package MeshWeaver.DataSetReader.Excel.Utils --version 2.0.3
                    
NuGet\Install-Package MeshWeaver.DataSetReader.Excel.Utils -Version 2.0.3
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MeshWeaver.DataSetReader.Excel.Utils" Version="2.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MeshWeaver.DataSetReader.Excel.Utils" Version="2.0.3" />
                    
Directory.Packages.props
<PackageReference Include="MeshWeaver.DataSetReader.Excel.Utils" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MeshWeaver.DataSetReader.Excel.Utils --version 2.0.3
                    
#r "nuget: MeshWeaver.DataSetReader.Excel.Utils, 2.0.3"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=MeshWeaver.DataSetReader.Excel.Utils&version=2.0.3
                    
Install MeshWeaver.DataSetReader.Excel.Utils as a Cake Addin
#tool nuget:?package=MeshWeaver.DataSetReader.Excel.Utils&version=2.0.3
                    
Install MeshWeaver.DataSetReader.Excel.Utils as a Cake Tool

MeshWeaver.DataSetReader.Excel.Utils

MeshWeaver.DataSetReader.Excel.Utils is a utility library that provides common functionality and abstractions for Excel file reading in the MeshWeaver ecosystem. It serves as the foundation for both binary (.xls) and OpenXML (.xlsx) format readers.

Overview

The library provides:

  • Core interfaces for Excel data reading
  • Common utility functions for Excel data processing
  • Error handling and exception types
  • ZIP archive handling for OpenXML formats
  • Format conversion utilities
  • Data type management

Core Components

IExcelDataReader Interface

The main interface for Excel data reading implementations:

public interface IExcelDataReader : IDataReader
{
    void Initialize(Stream fileStream);
    DataSet AsDataSet();
    DataSet AsDataSet(bool convertOADateTime);
    bool IsValid { get; }
    string Name { get; }
    int ResultsCount { get; }
    bool IsFirstRowAsColumnNames { get; set; }
}

Utility Functions

Data Conversion
public static class Helpers
{
    // Convert Excel OLE Automation date to DateTime
    public static object ConvertFromOATime(double value);
    
    // Convert escaped characters in strings
    public static string ConvertEscapeChars(string input);
    
    // Convert Int64 bits to double (for binary formats)
    public static double Int64BitsToDouble(long value);
}
Data Type Management
public static class Helpers
{
    // Fix and optimize data types in DataSet
    public static void FixDataTypes(DataSet dataset);
    
    // Handle duplicate column names
    public static void AddColumnHandleDuplicate(DataTable table, string columnName);
}

ZIP Archive Handling

public class ZipWorker
{
    // Access workbook and shared strings streams
    public Stream GetWorkbookStream();
    public Stream GetSharedStringsStream();
    public Stream GetStylesStream();
}

Constants and Formats

public static class ExcelConstants
{
    // Common Excel format constants
    public const int MaxWorksheetColumns = 16384;
    public const int MaxWorksheetRows = 1048576;
    public const int MaxWorksheetNameLength = 31;
}

Error Handling

Exception Types

  • BiffRecordException - For BIFF record parsing errors
  • HeaderException - For header parsing errors
  • ExcelReaderException - Base exception for Excel reading errors

Error Messages

public static class Errors
{
    public const string InvalidPassword = "Invalid password";
    public const string InvalidFile = "Invalid file";
    public const string NotSupported = "Not supported";
}

Features

  1. Format Support

    • Binary (.xls) format utilities
    • OpenXML (.xlsx) format utilities
    • Common abstractions for both formats
  2. Data Processing

    • Stream-based reading
    • Data type inference
    • Column name handling
    • Date/time conversion
    • Character encoding support
  3. Error Handling

    • Specialized exception types
    • Validation checks
    • Error messages
    • Recovery mechanisms
  4. Performance Optimizations

    • Efficient data type handling
    • Stream management
    • Memory optimization
    • Resource cleanup

Best Practices

  1. Resource Management

    using (var stream = File.OpenRead("data.xlsx"))
    {
        var reader = new ExcelReader();
        reader.Initialize(stream);
        // Process data
    }
    
  2. Data Type Handling

    var dataset = reader.AsDataSet();
    Helpers.FixDataTypes(dataset); // Optimize data types
    
  3. Error Handling

    try
    {
        reader.Initialize(stream);
        if (!reader.IsValid)
            throw new ExcelReaderException(reader.ExceptionMessage);
    }
    catch (BiffRecordException ex)
    {
        // Handle BIFF format errors
    }
    

Integration

With Excel Readers

public class ExcelReader : IExcelDataReader
{
    protected readonly ZipWorker ZipWorker;
    
    public void Initialize(Stream stream)
    {
        ZipWorker.Initialize(stream);
        // Initialize reader
    }
}

With Message Hub

services.AddMessageHub(hub => hub
    .ConfigureServices(services => services
        .AddTransient<IExcelDataReader, ExcelReader>()
    )
);
  • MeshWeaver.DataSetReader.Excel - Base Excel reader framework
  • MeshWeaver.DataSetReader.Excel.BinaryFormat - Legacy Excel format implementation
  • MeshWeaver.DataSetReader.Excel.OpenXmlFormat - Modern Excel format implementation
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on MeshWeaver.DataSetReader.Excel.Utils:

Package Downloads
MeshWeaver.DataSetReader.Excel.OpenXmlFormat

Package Description

MeshWeaver.DataSetReader.Excel.BinaryFormat

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 154 9 days ago
2.0.3 482 22 days ago
2.0.2 461 22 days ago
2.0.1 115 25 days ago
2.0.0 149 a month ago
2.0.0-preview3 101 2 months ago
2.0.0-Preview2 117 2 months ago
2.0.0-preview1 106 3 months ago
1.0.1 148 6 months ago
1.0.0 125 6 months ago