title: Create an Excel PivotTable from a DataTable
body: <p>I have a webservice that is hosting a large mass of pricing data, and returns the data relevant to some prescribed query parameters. The data comes back as a Datatable object (in C#) - the object type itself doesn't matter so much as the fact that the data goes directly into memory and is not on a spreadsheet in the host Excel object.</p>
  
  <p>Now, I want to create a pivottable off of this data.</p>
  
  <p>I've been looking high and low on the web, and I can't see anyone explaining how to do this. Is it impossible? It seems foolish to suggest VSTO as the only supported way of consuming webservice data going forward, but make pivottables off of that data impossible.</p>
  
  <p>The only solutions I have are kludges, and I want to make sure there isn't a graceful solution before I do one of these ugly things:</p>
  
  <ol>
  <li>Dump datatable to excel sheet and point pivottable to excel range.
  This is far from ideal because I'm either doing rowwise deletion
  over the entire dataset (slow as heck) or peaking at 2x memory
  consumption</li>
  <li>Dump datatable to filesystem and point pivottable to flatfile.
      This is even worse but at least doesn't have the memory drawback.</li>
  </ol>
  
  <p>Are these really the only ways to do this operation? There has to be something more graceful.</p>
  
  <p>DataTable: <a href="http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/system.data.datatable.aspx</a></p>
  
  <p>PivotCache: <a href="http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.pivottable.pivotcache(v=office.11).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.pivottable.pivotcache(v=office.11).aspx</a></p>