Thursday, May 26, 2011

Free Programatic Interface to Excel in C# - EPPlus

Needing a way to programatically create Excel spreadsheets, I found EPPlus and it works great. It took about 10 minutes to create my first multi-workbook excel file.
You can download it at epplus.codeplex.com.
My toy code:
private static void WriteExcelBrandsList(BrandAndCodeRepository brandsRepository, Choice choice)
{
  using (ExcelPackage pck = new ExcelPackage()) {
    //Create the worksheet for each list
    foreach (var listName in brandsRepository.GetLists())
    {
      ExcelWorksheet ws = pck.Workbook.Worksheets.Add(listName);
      ws.Cells["A1"].Value = "Brand";
      ws.Cells["B1"].Value = "Fieldwork";
      var brandAndCodes = brandsRepository.GetList(listName);
      int i = 2;
      foreach (var brandAndCode in brandAndCodes)
      {
          ws.Cells["A" + i].Value = brandAndCode.BrandId;
          ws.Cells["B" + i].Value = "2011-01";
          i++;
      }
    }
    string fileName = string.Format("C:\\BrandLists_{0}_{1}.xlsx", choice.Category, choice.Locale);
    Console.Out.WriteLine("writing to fileName = {0}", fileName);
    pck.SaveAs(new FileInfo(fileName));
  }
}

Wednesday, May 25, 2011

Austin on Rails, May 24, 2011

I drop in on the Austin on Rails community occasionally to get a taste of what's coming to .Net in a few years. Eighty people crammed into a stuffy room to catch the latest in Rails technology.
Matt Thompson gave an overview of CoffeeScript, a semantically more pleasant version of JavaScript that gets translated into real JavaScript.
Adam Michela, aka soopa, presented Sass, Syntactically Awesome Style Sheets, a layer of abstraction above css which get translated into real css files.
The pairing of the technologies was a nice touch by Damon Clinkscales since both will be in the next version of Rails and both are essentially the same thing - a more human language that gets translated down to a tried and true web component.

Tuesday, May 03, 2011

Agile Austin May 3, 2011 - Steven “Doc” List: The Agile Lego Game

Steven "Doc" List of ThoughtWorks led the Agile group in a fun game of learning agile principles by playing with Legos. One member of each team volunteered to be the "customer", our team was fortunate enough to have Scott Killen. The customer provided each team with a set of user stories like 'your animal should have wings'. We walked through three iterations of estimating, planning, building, and retrospection. The game was a fun way to learn Agile and get to know other members better.











C#: Does a Close() automatically call a Flush()

The following C# code always looked a little clunky to me, because a Close() should probably perform a flush as well. I quickly Googled around and my suspicions were confirmed that the Close() method would automatically do a Flush().
Response.Write(qdbXml);
Response.Flush();
Response.Close();
So while cleaning up some other code I removed the Flush() call. Then everything stopped working. I thought it was the other changes I made at first. Chrome gave this helpful message:
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
I restored the Flush() and everything worked great again. The Response object above is a System.Web.Mvc.Controller.Response object which doesn't necessarily work like some other stream objects and needs flushing before closing.
TIL not all stream objects behave alike and I can get in trouble by assuming hastily gathered Googled results apply to me.