|
| 1 | +# NPOI.Extensions |
| 2 | +This package is an extension to the https://github.com/tonyqus/npoi, as I found reading excel values with the basic interface a bit cumbersome. |
| 3 | + |
| 4 | +> On my pet projects I used less flexible helper functions for reading excel cell values. They always adressed just the needs of a given use-case and were not tested for flexibility and corner-case cenarios. |
| 5 | +
|
| 6 | +**My goal with this library is to have a stable, reliable, simple (unified) way to read values from excel cell.** |
| 7 | +To ensure this, project includes unit tests for the GetValue extension method, covering most of the situations a developer might need in an enterprise solution. |
| 8 | + |
| 9 | + |
| 10 | +## This library currently |
| 11 | + |
| 12 | +- **simplifies & unifies reading cell values into typed variables** |
| 13 | +- adds support to **map a sheet into a typed list** - *simple approach with 100% control over the mapping* |
| 14 | + |
| 15 | +*NOTE:* |
| 16 | + |
| 17 | +There's also a project (https://github.com/donnytian/Npoi.Mapper) which addresses mapping sheet to typed list, which requires a major change in the Map and ShouldMap function to be more widely usable (see: https://github.com/donnytian/Npoi.Mapper/issues/45). |
| 18 | + |
| 19 | +## Major extension functions |
| 20 | + |
| 21 | +**public T GetValue<T>(this IRow, index)** |
| 22 | +- **unifies access to cell value regardless of it's type** |
| 23 | +- allows to read into a typed output variable in a simple way |
| 24 | +- does a **safe null/blank cell access**, is able to map cell value (being it null or not) to Nullable<> types |
| 25 | +- allows to **read any cell as a formatted string** (the formatted content - that is shown inside the excel cell - is returned as a string) |
| 26 | +- handles reading of **formula results** into typed variable (we usually are interested in the result, not in the formula) |
| 27 | + |
| 28 | +--- |
| 29 | +**public List<T> MapTo<T>(this ISheet sheet, bool firstRowIsHeader, Func<ExcelRowMapper, T> rowMapper)** |
| 30 | +- **simplifies mapping the excel content into a typed list** |
| 31 | +- the rowMapperFunction allows to **get cell content by column header (title)**: rowMapper.GetValue<DateTime>("Order Date") |
| 32 | + |
| 33 | + |
| 34 | +## Getting started |
| 35 | + |
| 36 | +There's a **sample project** (and sample excel workbooks) for the mappign extensions, where also the GetValue<T> is used. |
| 37 | + |
| 38 | +The **XUnitTest** for the GetValueExtensions contains tests for all the functionality the GetValue<T> is intended to support. |
| 39 | + |
| 40 | +## License |
| 41 | +https://opensource.org/licenses/MIT, Copyright (c) 2020 by Balázs HIDEGHÉTY |
| 42 | + |
0 commit comments