topic | products | languages | extensions | |||||||
---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
|
The goal of this project is to simplify reading and writing Excel workbooks so that the developer needs only pass a collection of objects to write a workbook. Likewise, when reading a workbook the developer supplies a class with properties that map to column names to read a collection of those objects from the workbook.
Excel.IO takes a single dependency on the Open XML SDK and targets .NET Standard 2.0
- Easy to use developer API
- Write one or more worksheets per workbook by passing a collection of strongly typed objects
- Read one or more worksheets from a workbook into a collection of strongly typed objects
- Assumes workbook structure where the first row has column headers
- Reading multiple worksheets is a little inefficient
- Localisation isn't currently supported
Implement IExcelRow and define the columns of the spreadsheet as public properties:
public class Person : IExcelRow
{
public string SheetName { get => "People Sheet"; }
public string EyeColour { get; set; }
public int Age { get; set; }
public int Height { get; set; }
}
Then create instances and pass a collection to an instance of ExcelConverter to write a single sheet workbook with several rows:
var people = new List<Person>();
for (int i = 0; i < 10; i++)
{
people.Add(new Person
{
EyeColour = Guid.NewGuid().ToString(),
Age = new Random().Next(1, 100),
Height = new Random().Next(100, 200)
});
}
var excelConverter = new ExcelConverter();
excelConverter.Write(people, "C:\\somefolder\\people.xlsx");
Implement IExcelRow and define public properties with the same name as columns of the spreadsheet (we'll just reuse the same class from above):
public class Person : IExcelRow
{
public string SheetName { get => "People Sheet"; }
public string EyeColour { get; set; }
public int Age { get; set; }
public int Height { get; set; }
}
Then, ask an instance of ExcelConverter to read an IEnumerable from disk:
var excelConverter = new ExcelConverter();
var people = excelConverter.Read<Person>("C:\\somefolder\\people.xlsx");
foreach(var person in people)
{
//do something useful with the data
}
For feature requests or bugs, please post an issue on GitHub.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.