ClosedXML 0.100.1
Prefix ReservedSee the version list below for details.
dotnet add package ClosedXML --version 0.100.1
NuGet\Install-Package ClosedXML -Version 0.100.1
<PackageReference Include="ClosedXML" Version="0.100.1" />
paket add ClosedXML --version 0.100.1
#r "nuget: ClosedXML, 0.100.1"
// Install ClosedXML as a Cake Addin #addin nuget:?package=ClosedXML&version=0.100.1 // Install ClosedXML as a Cake Tool #tool nuget:?package=ClosedXML&version=0.100.1
Basic how to
ClosedXML is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API.
using (var workbook = new XLWorkbook())
{
var worksheet = workbook.Worksheets.Add("Sample Sheet");
worksheet.Cell("A1").Value = "Hello World!";
worksheet.Cell("A2").FormulaA1 = "=MID(A1, 7, 5)";
workbook.SaveAs("HelloWorld.xlsx");
}
For more information see the documentation or the wiki.
Release notes for 0.100.1
Added implicit conversion from decimal
to XLCellValue
, so it is not necessary to cast decimal
to double
explicitly.
Basically this now works, as it did pre-0.100:
decimal number = 15.5m;
ws.Cell(1,1).Value = number;
Release notes for 0.100
These are release notes for a version 0.100. We skipped a few version since the last release (0.97), because 0.100 should denote a major change at the very heart of ClosedXML. Not as clean break as I hoped, but close enough.
The list of all things that were changed from 0.97 to 0.100 is at the migration guide at the https://closedxml.readthedocs.io/en/latest/migrations/migrate-to-0.100.html
This is more like list of you should upgrade despite breaking changes 😃
Memory consumption significantly decreased
Memory consumption during saving of large data workbooks was significantly improved. Originally, ClosedXML workbook representation was converted to DocumentFomrat.OpenXML DOM representation and the DOM was then saved. Instead of creating whole DOM, sheet data (=cell values) are now directly streamed to the output file and aren't included in the DOM.
To demonstrate difference, see the before and after memory consumption of a report that generated 30 000 rows, 45 columns. Memory consumption has decreased from 2.08 GiB 🡆 0.8 GiB.
Save cells and strings through DOM: 2.08 GiB
Save cell and strings through streaming: 0.8 GiB
The purple area are bytes of uncompressed package zip stream.
Cell value is now strongly typed
IXLCell.Value
and IXLCellValue.CachedValue
have now type XLCellValue
. At the core, xlsx consists of addressable cells with a functions that transform a set of values in source cells to different values in target cells. Is is really important to represent potential values of cells by a sane type. All other things, pivot tables, auto filter, graphs rely on this premise.
Cell value has been represented as string text and a value. The string depended on the value, e.g. 0/1 for boolean. That has been the case since the beginning of the ClosedXML project (see the original XLCell). The value was also returned as an Object
.
This approach has several drawbacks
Object
is not suitable representation of cell value. User had no idea what kind of values could be returned as a cell value. Everything could also break down, if a new type would be returned (e.g.XLError
).- Setter could accept different types that the getter returned. E.g. it was possible to set cell value to a
IXLColumn
. - Values were always boxed/unboxed. That is not a problem for small amount of data, but it is not great for large workbooks.
- It caused an potentially buggy behavior in other places of the ClosedXML.
Value of a cell is not represented by a XLCellValue
structure. It is basically a union of one of possible types that can be value of a cell:
- blank
- boolean
- number
- text
- error
- datetime - basically number representing serial datetime, use serial datetime.
- duration - basically number representing serial datetime, use serial datetime
Since datetime and duration are basically masqaraded number, you can use XLCellValue.GetUnifiedNumber()
to get a backing number, no matter if the type is number, datetime and duration.
The structure contains implicit operators, as well as other methods to make transaction as seamless as possible
// Will use an implicit cast operator to convert string to XLCellValue and pass it to the Value setter
ws.Cell("A1").Value = "Text";
There is also a new singleton Blank.Value
that represent a blank value of a cell. Null is not blank. Empty string is not a blank value of a cell. Null instead of blank was considered and everything is just so much easier to work with, if blank is represented as a custom singleton type and not as a null.
XLCellValue
will be able to represent all values of a cell and won't be boxed/unboxed all the time.
Cell data type is no longer guessed
ClosedXML used to guess a data type from a value. It caused all sort of unexpected behaviors (e.g. text value Z12.31 has been converted to date time 12/30/2022 19:00). Date caused most problems, but other sometimes too (e.g. text "Infinity" was detected as a number).
This behavior was likely intended to emulate how user interacts with an Excel. Excel guesses type, but only if the cell Number Format is set to "General" (e.g. if NumberFormat is set to Text, there is no conversion even in Excel). Application is not human and doesn't have to interact with xlsx in the same way.
This behavior was removed. Type that is set is the type that will be returned. Note that although XLCellValue
can represent date and time as a different types, in reality that is only presentation logic for user. They are both just serial date time numbers.
Cell value now can be XLError or Blank
Cell value now can accurately represent error or a blank value.
ClosedXML used to throw on error value and cell couldn't contain an error. That was a significant problem, especially for formula calculation where formula referenced a cell that should contain an error value.
ClosedXML used to represent blank cell as an empty string, but no longer. It uses Blank.Value
singleton, wrapped in XLCellValue
. Also brings significant improvement in accuracy for CalcEngine evaluation.
Text to number coercion
Excel has a pretty complicated undocumented coercion process from text to number. It can convert fraction text (="1 1/2"*2
is 3), dates (e.g. ="1900-01-05"*2
is 10, though date format is culture specific), percent (e.g. ="100%"*2
), braces imply negative value (="(100%)"*2
= -2) and many more. That causes a significant problems for formula evaluation, especially if the source cell contains a date as a text, not as a date.
ClosedXml used to only convert test that looked like double
, it now coerces nearly everything Excel does. Coercion from dates should mostly work, but Excel has it's own database of acceptable formats and it's own format, while we rely on .NET Core infrastructure.
CalcEngine doesn't throw exceptions
Thanks to incorporation of XLError
to core of CalcEngine, the exceptions are no longer necessary and have been removed. Error is a normal value type that is used during formula evaluation (e.g. ISNA
accepts it and VLOOKUP
returns it).
Technically speaking CalcEngine can still throw MissingContextException
, but only if evaluation is not called from a cell, but from method like XLWorkbook.Evaluate
. Functions like ROW
just can't work without the context of the cell.
Unimplemented functions now return #NAME?
If you ever tried to use CalcEngine, you have encountered a dreaded The function *SomeFunctionwas not recognised.
exception.
ClosedXML will no longer throw an exception on unimplemented function, but will return #NAME?
error instead. It has several reasons
- It aligns behavior of user defined functions in like with predefined functions. ClosedXML doesn't throw anything on
=SOME.UNKNOWN.FUN(4)
, why should it throw on=LARGE(A1:A5,1)
? - By default, ClosedXML doesn't save calculated values. A portion of workbook that doesn't use unimplemented function should work correctly, maybe that is enough for some use case? Excel (nearly always) recalculates everything on load anyway.
Basically, the exception doesn't bring any benefit and only imposes costs. User can report missing function on #NAME?
error just like on exception.
Array literal can now be parsed
CalcEngine now can evaluate array literal expressions, so formulas like VLOOKUP(4, {1,2; 3,2; 5,3; 7,4}, 2)
now actually work.
Array processing is limited to argument parsing across formulas and CalcEngine still needs some love to process it work correctly. Array formulas are still not implemented.
Reimplementation of information and lookup functions
Information and lookup functions were reimplemented to take advantage of other improvements. They should now be compliant with Excel (with exception of wildcard search for VLOOKUP).
Documentation in the version control
Documentation is being moved from wiki to the ReadTheDocs. It has been there for since 2019, but we didn't actually had any documentation. Documentation is super important and ClosedXML lacks in that area. It is of course WIP, but it should improve over the time (see https://closedxml.readthedocs.io/en/latest/features/protect.html, https://closedxml.readthedocs.io/en/latest/features/cell-format.html#number-format or infamous https://closedxml.readthedocs.io/en/latest/tips/missing-font.html).
The move to ReadTheDocs has significant advantages:
- It is in version control. That means every PR now can contain modification to documentation.
- It is built as part of CI
- It is versioned.
- It uses ReStructured Text (rst) that has more rich style options and even plugins. Commonmark is heavily limited in style application.
- It can generate documentation from xml comments
- It can use references and includes. That means all examples can be in separate files and only included to documentation. Separate example files could be just complied and checked for correctness (we are not doing that ATM, but will likely do at some point in the future). That would solve the pesky issue of outdated examples in documentation.
Notes about breaking changes
We are not breaking the compatibility just because. Break imposes heavy penalty on users of the library. That makes it less likely to use it and that is definitely not the goal. Even the ClosedXML.Report must be fixed after every release.
That is not desirable situation. Version 1.0 and semantic versioning is certainly the goal. But it must be with an clear API that can endure some development between minor version. That is just not the case at the moment.
API will be reviewed along with the documentation and will be adjusted as necessary. ClosedXML will practice release early, release often. If breaking changes are not acceptable, stay on version that works and wait for 1.0 (though that will likely take at least a year, likely more... we are on a second decade).
Technically we do semver since forever, since Major version zero (0.y.z) is for initial development. Anything MAY change at any time. The public API SHOULD NOT be considered stable. ). Initial development for a decade /sigh.
Future plans
Similar to current release, the general plan is to work on neglected foundational things and bug fixes.
- Fix AutoFilter - doesn't work correctly, API is a mess and accepts any type. I wanted to have it done for 0.100 ¯_(ツ)_/¯
- Finish CalcEngine redesign with array formulas.
- Update XLParser to 1.6.2, I added PRs 162 and163 to improve speed by about factor of 3x (test dataset was parsed in 13 seconds vs 47 originally). But not enough time to upgrade the version ¯_(ツ)_/¯
- Housekeeping of PR - some PRs were merged, but most are still there.
- Cell sizing is a mess. Clean it up and fix AdjustToContent to be in line with what Excel does (research was done: https://github.com/ClosedXML/ClosedXML/wiki/Cell-Dimensions).
- Make a fuzzer for function evaluation that compares ClosedXML implementation with result from Excel
It is likely there will be 0.100.x to fix whatever bugs XLCellValue caused that weren't convered by tests.
Pivot tables won't get any love in 0.101, but hopefully in the next one. It is one of distinguishing features of ClosedXML and it has a lot of reported issues.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- DocumentFormat.OpenXml (>= 2.16.0)
- ExcelNumberFormat (>= 1.1.0)
- Microsoft.CSharp (>= 4.7.0)
- SixLabors.Fonts (>= 1.0.0-beta18)
- System.Buffers (>= 4.5.1)
- System.IO.Packaging (>= 6.0.0)
- System.Memory (>= 4.5.4)
- XLParser (>= 1.5.2)
NuGet packages (389)
Showing the top 5 NuGet packages that depend on ClosedXML:
Package | Downloads |
---|---|
ClosedXML.Report
ClosedXML.Report is a tool for report generation and data analysis in .NET applications through the use of Microsoft Excel. ClosedXML.Report is a .NET-library for report generation Microsoft Excel without requiring Excel to be installed on the machine that's running the code. |
|
CsvHelper.Excel.Core
An implementation of ICsvParser and ICsvSerializer from CsvHelper that reads and writes using the ClosedXml library. |
|
ClosedXML.Extensions.Mvc
MVC extensions for ClosedXML |
|
ClosedXML.Extensions.WebApi
WebApi extensions for ClosedXML |
|
SanteDB.BI
SanteDB Business Intelligence (BI) core logic. Provides structures for data sources, queries, reports, and report controls rendered in all SanteDB software solutions. |
GitHub repositories (34)
Showing the top 5 popular GitHub repositories that depend on ClosedXML:
Repository | Stars |
---|---|
nopSolutions/nopCommerce
ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
|
|
mini-software/MiniExcel
Fast, Low-Memory, Easy Excel .NET helper to import/export/template spreadsheet (support Linux, Mac)
|
|
serenity-is/Serenity
Business Apps Made Simple with Asp.Net Core MVC / TypeScript
|
|
YarnSpinnerTool/YarnSpinner
Yarn Spinner is a tool for building interactive dialogue in games!
|
|
open-rpa/openrpa
Free Open Source Enterprise Grade RPA
|
Version | Downloads | Last updated |
---|---|---|
0.104.2 | 238,726 | 11/15/2024 |
0.104.1 | 964,951 | 9/30/2024 |
0.104.0-rc1 | 36,656 | 9/17/2024 |
0.104.0-preview2 | 319,189 | 10/26/2023 |
0.103.0-beta | 27,550 | 9/28/2023 |
0.102.3 | 1,893,267 | 7/18/2024 |
0.102.2 | 7,002,086 | 1/5/2024 |
0.102.1 | 4,638,383 | 8/18/2023 |
0.102.0 | 1,829,686 | 6/24/2023 |
0.102.0-rc | 6,681 | 6/18/2023 |
0.101.0 | 2,936,832 | 4/9/2023 |
0.101.0-rc | 4,762 | 4/1/2023 |
0.100.3 | 3,741,249 | 1/12/2023 |
0.100.2 | 61,249 | 1/10/2023 |
0.100.1 | 27,183 | 1/9/2023 |
0.100.0 | 128,148 | 1/9/2023 |
0.97.0 | 4,371,693 | 10/21/2022 |
0.96.0 | 6,409,019 | 6/29/2022 |
0.95.4 | 22,302,362 | 12/16/2020 |
0.95.3 | 8,677,986 | 5/25/2020 |
0.95.2 | 721,936 | 4/26/2020 |
0.95.1 | 218,371 | 4/23/2020 |
0.95.0 | 1,173,861 | 4/15/2020 |
0.95.0-beta2 | 102,738 | 8/21/2019 |
0.95.0-beta1 | 44,426 | 4/4/2019 |
0.94.2 | 6,756,121 | 12/18/2018 |
0.94.0 | 70,550 | 12/12/2018 |
0.94.0-rc2 | 5,326 | 11/29/2018 |
0.94.0-rc1 | 8,549 | 11/11/2018 |
0.93.1 | 1,094,199 | 8/7/2018 |
0.93.0 | 506,837 | 6/25/2018 |
0.93.0-rc3 | 8,162 | 6/7/2018 |
0.93.0-rc2 | 4,257 | 5/31/2018 |
0.93.0-beta4 | 4,735 | 5/14/2018 |
0.93.0-beta2 | 5,406 | 4/26/2018 |
0.93.0-beta1 | 2,927 | 4/19/2018 |
0.92.1 | 1,192,243 | 4/10/2018 |
0.92.0-beta1 | 5,994 | 3/22/2018 |
0.91.1 | 62,110 | 4/4/2018 |
0.91.0 | 309,286 | 1/31/2018 |
0.91.0-beta3 | 4,268 | 1/23/2018 |
0.91.0-beta2 | 14,578 | 12/8/2017 |
0.91.0-beta1 | 2,960 | 11/29/2017 |
0.90.0 | 758,455 | 10/23/2017 |
0.90.0-beta2 | 3,264 | 10/6/2017 |
0.89.0 | 400,328 | 9/12/2017 |
0.89.0-beta1 | 5,319 | 8/23/2017 |
0.88.0 | 226,295 | 7/24/2017 |
0.88.0-beta1 | 10,556 | 7/10/2017 |
0.87.1 | 1,766,298 | 4/3/2017 |
0.86.0 | 436,353 | 1/6/2017 |
0.85.0 | 347,122 | 12/7/2016 |
0.80.1 | 744,689 | 9/15/2016 |
0.76.0 | 1,694,173 | 12/16/2014 |
0.75.0 | 214,147 | 9/17/2014 |
0.74.0 | 43,424 | 8/10/2014 |
0.73.0 | 40,121 | 6/24/2014 |
0.72.3 | 29,051 | 6/4/2014 |
0.72.2 | 4,712 | 6/4/2014 |
0.72.1 | 58,693 | 6/4/2014 |
0.72.0 | 11,520 | 6/4/2014 |
0.71.1 | 17,893 | 5/26/2014 |
0.70.0 | 13,340 | 5/18/2014 |
0.69.2 | 166,943 | 10/3/2013 |
0.69.1 | 87,338 | 8/15/2013 |
0.69.0 | 7,651 | 8/10/2013 |
0.68.1 | 106,729 | 10/20/2012 |
0.68.0 | 6,175 | 10/12/2012 |
0.67.2 | 24,146 | 8/14/2012 |
0.67.1 | 4,751 | 8/13/2012 |
0.67.0 | 4,880 | 8/12/2012 |
0.66.1 | 5,557 | 7/28/2012 |
0.66.0 | 5,138 | 7/18/2012 |
0.65.2 | 10,384 | 4/21/2012 |
0.64.0 | 24,123 | 2/4/2012 |