AMain.ExcelHelper
1.4.0
dotnet add package AMain.ExcelHelper --version 1.4.0
NuGet\Install-Package AMain.ExcelHelper -Version 1.4.0
<PackageReference Include="AMain.ExcelHelper" Version="1.4.0" />
<PackageVersion Include="AMain.ExcelHelper" Version="1.4.0" />
<PackageReference Include="AMain.ExcelHelper" />
paket add AMain.ExcelHelper --version 1.4.0
#r "nuget: AMain.ExcelHelper, 1.4.0"
#:package AMain.ExcelHelper@1.4.0
#addin nuget:?package=AMain.ExcelHelper&version=1.4.0
#tool nuget:?package=AMain.ExcelHelper&version=1.4.0
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.
- 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.
- 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.
- 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.
- Pull requests should have a single commit. If you have multiple commits, squash them into a single commit before requesting a pull.
- 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 | Versions 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 | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.6.2
- ClosedXML (>= 0.96.0)
- DocumentFormat.OpenXml (>= 2.16.0)
- ExcelDataReader (>= 3.7.0)
- ExcelNumberFormat (>= 1.1.0)
- FastMember.Signed (>= 1.5.0)
- System.IO.FileSystem.Primitives (>= 4.3.0)
- System.IO.Packaging (>= 8.0.1)
-
net8.0
- ClosedXML (>= 0.96.0)
- DocumentFormat.OpenXml (>= 2.16.0)
- ExcelDataReader (>= 3.7.0)
- ExcelNumberFormat (>= 1.1.0)
- FastMember.Signed (>= 1.5.0)
- System.IO.FileSystem.Primitives (>= 4.3.0)
- System.IO.Packaging (>= 8.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added .NET 8 support; the package now targets net462 and net8.0. On .NET 8 the reader registers the code page encodings ExcelDataReader needs to read Excel files. TimeSpan values read from Excel are rounded to the nearest millisecond, so .NET 8 returns the same values as .NET Framework. The writer now sizes columns the way Excel's AutoFit does, using a built in table of font widths instead of System.Drawing, so sizing works the same on any OS.