Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Guys :)

I got another issue with C# - I am looking for a way of collapsing pivot table fields. Generally situation is as follows:

http://i45.tinypic.com/cnx37.jpg[^]

I know that in VBA it can be done by this peace of code:
VB
ActiveSheet.PivotTables("PivotTableName").PivotFields("PivotFieldName").ShowDetail = False

Does anyone have an idea how it can be done with a C#?

I've already looked at MSDN, but it hardly gives a good example. Other sources also gave nothing to kick-start...

Thanks a lot in advance!
Posted
Updated 4-Apr-13 21:35pm
v4
Comments
Maciej Los 5-Apr-13 3:34am    
What have you done till now?
MK-Gii 5-Apr-13 3:51am    
I have read a bunch of pages in MSDN and other forums. Looks like nobody has been trying to do this before... Overarly it looks like a simple tasks, but still strugling to find the right function to do it...

1 solution

Since you gave the VBA code im going to assume that it can be done this way:
        Excel.Application oXL;
	Excel._Workbook oWB;
	Excel._Worksheet oSheet;
	Excel.Range oRng;

	try
	{
		//Start Excel and get Application object.
		oXL = new Excel.Application();
		oXL.Visible = true;

		//Get a new workbook.
		oWB = (Excel._Workbook)(oXL.Workbooks.Add( Missing.Value ));
		oSheet = (Excel._Worksheet)oWB.ActiveSheet;
                oSheet.PivotTables("PivotTableName").PivotFields("PivotFieldName").ShowDetail = False
/pre>
 
Share this answer
 
Comments
MK-Gii 5-Apr-13 5:20am    
Worked like a charm - you're 'ma man!
Kenneth Haugland 5-Apr-13 5:57am    
If you have the VBA code you can, at leat to my knowlage, always solve the problems using simular techniques:-)
MK-Gii 5-Apr-13 6:12am    
Good hint. Didn't even thought about this actually ;] Now I'll try that approach in the future before overburding you guys with dummy questions x]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900