After Thought

Posts Tagged ‘Mic

Now you can insert records into Excel using ExcelMapper

leave a comment »

You can now use ExcelMapper to insert records into Excel as well. Continuing with the same User example, we can insert a User (John Doe) into Excel using ExcelMapper.

ExcelMapper.SetUp();
IRepository repository = ServiceLocator.Current.GetInstance<IRepository>();

List<User> users = new List<User>
{
   new User
   {
       Id = 1,
       LastName = "Doe",
       FirstName = "John
       DateOfBirth  = Convert.ToDateTime("2/2/1990")
   }
};
repository.Put<User>(users);

Note that User DTO was generated using BuildDTOsFromExcel.exe.

repository.Put<User>(User) saves the Users List into Excel. Since we don’t have the concept of unique keys yet, it can only insert and not update.

Written by shashankshetty

July 27, 2009 at 10:11 am

Posted in C#, ExcelMapper, Microsoft Excel

Tagged with , , ,