views:

473

answers:

2

Hi, does anyone know if there's any good online tutorial for building pivot tables using Interop.Excel.PivotTable?

These are the only two I can find:

http://blogs.msdn.com/andreww/archive/2008/07/25/creating-a-pivottable-programmatically.aspx

http://www.dreamincode.net/code/snippet1217.htm

And I'm looking for more complicated examples?

Thanks,

A: 

you can read in MSDN with interop.Excel

A: 

If you're going to write your own COM Excel code, you aren't going to use the Wizard. Simply record a macro of a pivot table creation and translate the resultant VBA into your language (C#?) Record macros of yourself playing around with pivot tables and you'll soon get a feel for how to write this code.

Some words of warning:

  • The pivot table API sometimes changes between versions, so what works in one installation may not work in others. Test!
  • Macro code cannot always be directly translated. There are implied order-of-operation and read-only issues that recorded macros will not show you. If you get stuck, it's usually because you need to do things in the correct order. These issues are hard to resolve. E.G. - I believe charts are read-only once you relocate them to a separate sheet, so do relocation last!
Greg