AMain.ExcelHelper.C1 1.4.0

dotnet add package AMain.ExcelHelper.C1 --version 1.4.0
                    
NuGet\Install-Package AMain.ExcelHelper.C1 -Version 1.4.0
                    
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="AMain.ExcelHelper.C1" Version="1.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AMain.ExcelHelper.C1" Version="1.4.0" />
                    
Directory.Packages.props
<PackageReference Include="AMain.ExcelHelper.C1" />
                    
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 AMain.ExcelHelper.C1 --version 1.4.0
                    
#r "nuget: AMain.ExcelHelper.C1, 1.4.0"
                    
#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.
#:package AMain.ExcelHelper.C1@1.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AMain.ExcelHelper.C1&version=1.4.0
                    
Install as a Cake Addin
#tool nuget:?package=AMain.ExcelHelper.C1&version=1.4.0
                    
Install as a Cake Tool

ExcelHelper

A library for reading and writing Excel files. Extremely fast, flexible, and easy to use. Supports reading and writing of custom class objects.

This library is based on the awesome library CsvHelper for reading and writing CSV files by Josh Close. We use the awesome library for reading Excel files in all formats (including the binary BIFF8 and earlier formats as well as the modern OpenXML formats), ExcelDataReader. Lastly we use the awesome library for writing native OpenXML based Excel files ClosedXML, which is layered on top of the Microsoft OpenXML libraries. Since we rely on OpenXML for writing Excel files, this library can only write Excel files in the modern OpenXML (.xlsx) formats. But it can read them in any format.

This library is re-write of the CsvHelper library to support Excel file reading and writing so it has diverged somewhat from the original CsvHelper API in order to support the features we need with better support for Excel file reading and writing. You can find the awesome CsvHelper library for processing CSV files here:

https://github.com/JoshClose/CsvHelper

You can find the awesome Open Source libraries we rely upon for Excel reading and writing here:

https://github.com/ExcelDataReader/ExcelDataReader

https://github.com/ClosedXML/ClosedXML

Install

To install ExcelHelper, run the following command in the Package Manager Console

PM> Install-Package AMain.ExcelHelper

There is also a version built on the commercial C1.Excel library from Mescius:

PM> Install-Package AMain.ExcelHelper.C1

Supported frameworks

Package .NET Framework .NET 8
AMain.ExcelHelper 4.6.2 or later net8.0, on any OS
AMain.ExcelHelper.C1 4.8 or later net8.0, on any OS

Column and row sizing

Both writers size columns to fit their contents the way Excel's AutoFit does, without System.Drawing or the fonts being installed. They use a built in table of the character widths Windows GDI gives for 12 common fonts (Arial, Arial Narrow, Calibri, Calibri Light, Cambria, Consolas, Courier New, Georgia, Segoe UI, Tahoma, Times New Roman and Verdana) in every style from 6 to 36 points. Widths are usually within a pixel of Excel's. Other fonts are measured as Calibri, larger sizes are scaled, and East Asian text is estimated, so those can be a few pixels off.

Excel shows a cell on one line unless it wraps text, which the writers do not turn on, so a line break in a cell does not make the column narrower or the row taller.

The table is src/ExcelHelper/TextMeasurement/FontWidths.bin. To add a font or regenerate it, edit the list in src/FontWidthGenerator/Program.cs and run this on Windows with the fonts installed:

cd src
dotnet run --project FontWidthGenerator -- ExcelHelper\TextMeasurement\FontWidths.bin

Building and testing

Build the solution in src with Visual Studio 2022, Rider, or the dotnet CLI. The tests run on both .NET Framework and .NET 8:

cd src
dotnet test ExcelHelper.sln

The C1 tests need an activated C1 license on the build machine (see License below).

Documentation

TODO: This needs to be done

License

Dual licensed

Microsoft Public License (MS-PL)

http://www.opensource.org/licenses/MS-PL

Apache License, Version 2.0

http://opensource.org/licenses/Apache-2.0

Commercial license for C1.Excel can be generated for builds as explained here (you need an active license to do that):

https://developer.mescius.com/componentone/docs/license/online-license/license-user-controls.html

Contribution

Want to contribute? Great! Here are a few guidelines.

  1. If you want to do a feature, post an issue about the feature first. Some features are intentionally left out, some features may already be in the works, or I may have some advice on how I think it should be done. I would feel bad if time was spent on some code that won't be used.
  2. If you want to do a bug fix, it might not be a bad idea to post about it too. I've had the same bug fixed by multiple people at the same time before.
  3. All code should have a unit test. If you make a feature, there should be significant tests around the feature. If you do a bug fix, there should be a test specific to that bug so it doesn't happen again.
  4. Pull requests should have a single commit. If you have multiple commits, squash them into a single commit before requesting a pull.
  5. Try and follow the code styling already in place. If you have ReSharper there is a dotsettings file included and things should automatically be formatted for you.
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Framework net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

  • net8.0

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.0 55 12/3/2026
1.1.1 402 6/30/2025
1.0.5 387 5/14/2025
1.0.4 353 5/14/2025
1.0.3 311 8/7/2024

Added .NET 8 support; the package now targets net48 and net8.0, on any OS. The writer now sizes columns the way Excel's AutoFit does, using a built in table of font widths instead of System.Drawing, so it no longer needs Windows or the fonts installed. TimeSpan values read from Excel are rounded to the nearest millisecond, so .NET 8 returns the same values as .NET Framework.