MeshWeaver.DataSetReader.Excel.OpenXmlFormat
2.0.3
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package MeshWeaver.DataSetReader.Excel.OpenXmlFormat --version 2.0.3
NuGet\Install-Package MeshWeaver.DataSetReader.Excel.OpenXmlFormat -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.OpenXmlFormat" 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.OpenXmlFormat" Version="2.0.3" />
<PackageReference Include="MeshWeaver.DataSetReader.Excel.OpenXmlFormat" />
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.OpenXmlFormat --version 2.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MeshWeaver.DataSetReader.Excel.OpenXmlFormat, 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.OpenXmlFormat&version=2.0.3
#tool nuget:?package=MeshWeaver.DataSetReader.Excel.OpenXmlFormat&version=2.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MeshWeaver.DataSetReader.Excel.OpenXmlFormat
MeshWeaver.DataSetReader.Excel.OpenXmlFormat is a specialized implementation for reading modern Excel (.xlsx) files using the Office Open XML format. It provides comprehensive support for reading Excel 2007+ workbooks with their XML-based structure.
Overview
The library provides:
- Complete Office Open XML format support
- Excel 2007+ workbook reading
- XML-based structure parsing
- Shared string handling
- Style and formatting support
- Cell type conversion
Architecture
Core Components
ExcelOpenXmlReader
Main reader implementation providing:
- ZIP archive handling
- XML content parsing
- Sheet data extraction
- Cell value conversion
Workbook Components
- XlsxWorkbook - Workbook structure and metadata
- XlsxWorksheet - Individual worksheet handling
- XlsxStyles - Style definitions and formatting
- XlsxDimension - Sheet dimensions and references
OpenXML Structure Support
Package Components
- Workbook XML
- Worksheet XMLs
- Shared Strings XML
- Styles XML
- Relationships XML
XML Namespaces
public static class Namespaces
{
public const string SpreadsheetMl =
"http://schemas.openxmlformats.org/spreadsheetml/2006/main";
public const string Relationships =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships";
}
Usage Examples
Basic File Reading
public async Task<IDataSet> ReadXlsxFile(Stream stream)
{
var reader = new ExcelOpenXmlReader();
reader.Initialize(stream);
var dataSet = new DataSet();
while (reader.Read())
{
// Process rows
for (int i = 0; i < reader.FieldCount; i++)
{
var value = reader.GetValue(i);
// Handle cell value
}
}
return dataSet;
}
Reading with Shared Strings
private object GetCellValue(XElement cell, XlsxWorkbook workbook)
{
var cellType = cell.Attribute("t")?.Value;
var value = cell.Element(ns + "v")?.Value;
if (cellType == "s") // Shared string
{
return workbook.SharedStrings[int.Parse(value)];
}
return value;
}
Style Handling
private object FormatCellValue(object value, XlsxXf style)
{
if (style.ApplyNumberFormat && IsDateTimeStyle(style.NumFmtId))
{
return ConvertFromOATime((double)value);
}
return value;
}
Advanced Features
ZIP Archive Handling
public class ZipWorker
{
public Stream GetWorkbookStream()
{
return GetEntryStream("xl/workbook.xml");
}
public Stream GetSharedStringsStream()
{
return GetEntryStream("xl/sharedStrings.xml");
}
}
Dimension Management
public class XlsxDimension
{
public int FirstRow { get; }
public int LastRow { get; }
public int FirstCol { get; }
public int LastCol { get; }
public XlsxDimension(string reference)
{
// Parse Excel dimension reference (e.g., "A1:Z100")
}
}
XML Structure
Workbook XML
<workbook xmlns="...">
<sheets>
<sheet name="Sheet1" sheetId="1" r:id="rId1"/>
<sheet name="Sheet2" sheetId="2" r:id="rId2"/>
</sheets>
</workbook>
Worksheet XML
<worksheet xmlns="...">
<dimension ref="A1:Z100"/>
<sheetData>
<row r="1">
<c r="A1" t="s">
<v>0</v>
</c>
</row>
</sheetData>
</worksheet>
Best Practices
Memory Management
- Use streaming XML parsing
- Handle large shared string tables
- Manage ZIP archive resources
- Clean up temporary streams
Performance
- Cache shared strings
- Optimize XML parsing
- Use efficient cell access
- Minimize memory allocations
Error Handling
- Validate XML structure
- Handle corrupt ZIP archives
- Manage missing components
- Validate cell references
Format Support
- Handle all cell types
- Support date/time formats
- Process custom number formats
- Manage style inheritance
Integration
With Base Excel Reader
public class OpenXmlFormatReader : ExcelDataSetReaderBase
{
protected override IExcelDataReader GetExcelDataReader(Stream stream)
{
var reader = new ExcelOpenXmlReader();
reader.Initialize(stream);
return reader;
}
}
With Message Hub
services.AddMessageHub(hub => hub
.ConfigureServices(services => services
.AddSingleton<IExcelReaderFactory>(provider =>
new ExcelReaderFactory())
.AddTransient<IDataSetReader, OpenXmlFormatReader>()
)
);
Error Handling
The library provides detailed error information for:
- Invalid XML structure
- Corrupt ZIP archives
- Missing package parts
- Invalid cell references
- Format conversion errors
Related Projects
- MeshWeaver.DataSetReader.Excel - Base Excel reader framework
- MeshWeaver.DataSetReader.Excel.BinaryFormat - Legacy Excel format implementation
- MeshWeaver.DataStructures - Core data structures
Product | Versions 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
- MeshWeaver.DataSetReader.Excel.Utils (>= 2.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MeshWeaver.DataSetReader.Excel.OpenXmlFormat:
Package | Downloads |
---|---|
MeshWeaver.DataSetReader.Excel
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.1.0 | 146 | 4/6/2025 |
2.0.3 | 477 | 3/24/2025 |
2.0.2 | 450 | 3/24/2025 |
2.0.1 | 104 | 3/21/2025 |
2.0.0 | 142 | 3/20/2025 |
2.0.0-preview3 | 95 | 2/28/2025 |
2.0.0-Preview2 | 103 | 2/10/2025 |
2.0.0-preview1 | 92 | 1/6/2025 |
1.0.1 | 124 | 10/8/2024 |
1.0.0 | 114 | 10/8/2024 |