https://github.com/mustaddon/arraytoexcel
Create Excel from Array (List, DataTable, DataSet, ...)
https://github.com/mustaddon/arraytoexcel
array converter dataset datatable dictionary dotnet excel list xlsx
Last synced: 10 months ago
JSON representation
Create Excel from Array (List, DataTable, DataSet, ...)
- Host: GitHub
- URL: https://github.com/mustaddon/arraytoexcel
- Owner: mustaddon
- License: mit
- Created: 2020-02-04T12:09:23.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-12-06T10:23:21.000Z (about 1 year ago)
- Last Synced: 2025-03-29T07:08:12.768Z (11 months ago)
- Topics: array, converter, dataset, datatable, dictionary, dotnet, excel, list, xlsx
- Language: C#
- Homepage:
- Size: 313 KB
- Stars: 38
- Watchers: 3
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ArrayToExcel [](http://badge.fury.io/nu/ArrayToExcel)
Create Excel from Array (List, DataTable, DataSet, ...)
### Example 1: Create with default settings
```C#
using ArrayToExcel;
var items = Enumerable.Range(1, 10).Select(x => new
{
Prop1 = $"Text #{x}",
Prop2 = x * 1000,
Prop3 = DateTime.Now.AddDays(-x),
});
var excel = items.ToExcel();
```
Result:
[example1.xlsx](https://github.com/mustaddon/ArrayToExcel/raw/master/Examples/example1.xlsx)

### Example 2: Rename sheet and columns
```C#
var excel = items.ToExcel(schema => schema
.SheetName("Example name")
.ColumnName(m => m.Name.Replace("Prop", "Column #")));
```
Result:
[example2.xlsx](https://github.com/mustaddon/ArrayToExcel/raw/master/Examples/example2.xlsx)

### Example 3: Sort columns
```C#
var excel = items.ToExcel(schema => schema
.ColumnSort(m => m.Name, desc: true));
```
Result:
[example3.xlsx](https://github.com/mustaddon/ArrayToExcel/raw/master/Examples/example3.xlsx)

### Example 4: Custom column's mapping
```C#
var excel = items.ToExcel(schema => schema
.AddColumn("MyColumnName#1", x => new CellHyperlink($"https://www.google.com/search?q={x.Prop1}", x.Prop1))
.AddColumn("MyColumnName#2", x => $"test:{x.Prop2}")
.AddColumn("MyColumnName#3", x => x.Prop3));
```
Result:
[example4.xlsx](https://github.com/mustaddon/ArrayToExcel/raw/master/Examples/example4.xlsx)

### Example 5: Additional sheets
```C#
var excel = items.ToExcel(schema => schema
.SheetName("Main")
.AddSheet(extraItems));
```
Result:
[example5.xlsx](https://github.com/mustaddon/ArrayToExcel/raw/master/Examples/example5.xlsx)

### Example 6: Create from DataSet
```C#
var dataSet = new DataSet();
for (var i = 1; i <= 3; i++)
{
var table = new DataTable($"Table{i}");
dataSet.Tables.Add(table);
table.Columns.Add($"Column {i}-1", typeof(string));
table.Columns.Add($"Column {i}-2", typeof(int));
table.Columns.Add($"Column {i}-3", typeof(DateTime));
for (var x = 1; x <= 10 * i; x++)
table.Rows.Add($"Text #{x}", x * 1000, DateTime.Now.AddDays(-x));
}
var excel = dataSet.ToExcel();
```
Result:
[example6.xlsx](https://github.com/mustaddon/ArrayToExcel/raw/master/Examples/example6.xlsx)

[Example.ConsoleApp](https://github.com/mustaddon/ArrayToExcel/tree/master/Examples/Example.ConsoleApp/Program.cs)