Condividi tramite


Office Activity, or Wrapping Existing Code Quickly

One of the nice things about the WF activity model is that you can pretty rapidly take existing code and expose that functionality out as a WF activity.  I was reading on Doug's blog, and noticed that he's got a series going where he will create an Open XML document (the XML based representation of the next version of Office documents).  He's got two parts so far, a Word document and an Excel spreadsheet creator.  I've taken those and wrapped those into WF activities that are available on the community site (Word document activity, Excel spreadsheet activity).  Make sure to check out the implementation notes on Doug's site, if you want to do some large scale number crunching in Excel, this would be a good start, but you would want to change so that it doesn't write out a single cell at a time.  Formatting and formulas are also not included in this sample, but you could easily extend to support these by diving through some other Open XML posts.

The Excel activity takes in a dictionary with cell references and then its values (see code below).

          Dictionary<string,object> cellContents = new Dictionary<string, object>();
         cellContents.Add("A1", "hello World");
         cellContents.Add("B2", 34);
         cellContents.Add("C5", 232);

There is one trick to remember and that's to add the reference to WindowsBase (on my machine, located at: C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll) if you're looking around for System.IO.Packaging.

When he gets a Powerpoint post up there, I will wrap that up in an activity as well.  If anyone extends these to support some more advanced scenario, or have a really nice design experience (think grid control), please let me know, and we'll get your version hosted on https://wf.netfx3.com!

Let me know what you think!