views:

45

answers:

1

Given the following assemblage of classes (contrived):

public class School {
  [PrimaryKey]
  public string Name {get; set;}
  [Set]
  public IList<Teacher> Teachers {get; set;}

public class Teacher {
  [PrimaryKey]
  public string Name {get; set;}

I'd like to have the object hierarchy serialized into a single sheet of an xlsx file, like

School.Name            Teacher.Name
Waldorf College        Ms. Briggs
Waldorf College        Mr. Smith
Starfleet Academy      Mr. Spock
Starfleet Academy      Mr. Sulu
Starfleet Academy      Mr. Kirk

I'd then like to deserialize any (sensible) modifications to the xlsx file, creating a new copy of School, and its associated Teachers.

Does anyone know of something similar to this that doesn't require touching the OpenXML libraries too much?

Thanks.

A: 

You can always use ADO.Net and LINQ.

Using ADO.Net to Create and Alter an Excel File... <= first link I found hopefully it helps.

Matthew Whited
Sorry, these objects are going to be persisted to the database, and I don't want to mess with interop; I'll go the CSV route first.
hoffmanc
ADO.Net isn't interop.
Matthew Whited
If you are worried about using interop to create a new file then just create an excel file as a template and either have it beside the exe or as a resource. Then you can just write to it with ADO.Net
Matthew Whited