GithubHelp home page GithubHelp logo

longde123 / excel-io Goto Github PK

View Code? Open in Web Editor NEW

This project forked from officedev/excel-io

0.0 1.0 0.0 106 KB

A utility library that makes it easy to read and write Excel workbooks using C#

License: MIT License

C# 100.00%

excel-io's Introduction

topic products languages extensions
sample
office-excel
office-365
csharp
contentType createdDate
tools
6/7/2018 11:27:43 AM

Excel.IO

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

Features

  • 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

Limitations

  • Assumes workbook structure where the first row has column headers
  • Reading multiple worksheets is a little inefficient
  • Localisation isn't currently supported

Example: Writing a worksheet

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");

Example: Reading a worksheet

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
}

Feedback

For feature requests or bugs, please post an issue on GitHub.

Contributing

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.

excel-io's People

Contributors

jdinis avatar isaacaflores2 avatar craigomatic avatar microsoftopensource avatar o365devx avatar joaopedrodinis avatar msftgits avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.