Skip to content
Jos de Weger edited this page Jun 16, 2018 · 14 revisions

Getting started

This is the documentation for the SheetToObjects library. Not interested in the in depth docs? See an example below to get you started:

  1. Create a configuration, mapping each column to a property on your model/POCO:
var sheetMapper = new SheetMapper()
    .AddConfigFor<SomeModel>(cfg => cfg
        .AddColumn(column => column.WithHeader("First Name").IsRequired().MapTo(m => m.FirstName))
        .AddColumn(column => column.WithHeader("Middle Name").MapTo(m => m.MiddleName))
        .AddColumn(column => column.WithHeader("Last Name").IsRequired().MapTo(m => m.LastName))
        .AddColumn(column => column.WithHeader("Email").Matches("^\S+@\S+$").MapTo(m => m.Email))
        .AddColumn(column => column.WithHeader("Age").WithCustomRule<int>(age => age > 18 && age <= 67).MapTo(m => m.Email))
    );
  1. Get the sheetdata using one of the adapters (e.g. Google Sheets):
var sheet = await _googleSheetProvider.GetAsync(mySheetId, "'My SheetName'!A1:H5", myApiKey);
  1. Do the actual mapping, which returns a result object containing validation and mapped models:
var result = _sheetMapper.Map<MyModel>(sheet);
Clone this wiki locally