C# Late Binding and PivotCaches

J

jtoulier

Hello,

I have a problem creating PivotTables in Excel. If we use early binding
we have no problem, but if we use late binding we have the following
problem:

EARLY BINDING (works fine)
**********************************
Workbook oWorkbook;

// oWorkbook is a valid Excel.Workbook

// for example this line works fine
oWorksheet = (Worksheet)oWorkbook.ActiveSheet;

// these lines work fine too !!
PivotCaches oPivotCaches;
oPivotCaches = (Excel.PivotCaches)oWorkbook.PivotCaches();


LATE BINDING (same as above)
*************************************
object oWorkbook;

// oWorkbook is a valid Excel.Workbook

// for example this line works fine
oWorksheet = oWorkbook.GetType().InvokeMember("ActiveSheet",
BindingFlags.GetProperty, null, oWorkbook, null);

// these lines don't work !!
object oPivotCaches;
oPivotCaches = oWorkbook.GetType().InvokeMember("PivotCaches",
BindingFlags.GetProperty, null, moWorkbook, null);

// the error is:
An unhandled exception of type
'System.Reflection.TargetInvocationException' occurred in mscorlib.dll

Additional information: Exception has been thrown by the target of an
invocation.


Thanks a lot

Joseph Toulier
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top