Install the Open XML SDK , it contains a tool called the Open XML SDK Performance Tool.
How to use it:
Open Excel and create a file containing a pivot table. Save it and open it using the Performance tool. This tool has the option "Reflect the code", so you can see how to create the same Excel using C # code.
source share