I'm trying to control an Excel (2010) PivotTable from a VSTO (excel AddIn) in C# (4.0). I've got no problem adding PivotFields (Dimensions) and DataFields (Measures) to the PivotTable. The problem is I can't remove a DataField.
My DataField is a PivotField object. I've tried :
myDataField.Hidden = true;
myDataField.DisplayInReport = false;
myDataField.Orientation = XlPivotFieldOrientation.xlHidden;
// This last one is what I use to remove a (Dimension) PivotField
Every one of these lines throws a COM Exception with absolutely no information in it. The only thing I have is the message : "Exception de HRESULT : 0x800A03EC", which seems to be common to every VSTO exception.
If anyone has a solution, that would help me a lot.