在VS2005中对Excel进行编程,首先要在对象引用中添加Microsoft Excel Object Libray,对于Office2003,应该是Microsoft Excel 11 Object Libray,Office2007则是Microsoft Excel 12 Object Libray.
添加引用的方法可以参见文章
按照上述文章,我第一次添加Excel对象库的时候,引用中也出现了Excel,但是程序一直编译不过,后来再查资料,在MSDN的一篇文章发现了问题所在:
When you select the referenced IA in Solution Explorer, if the Copy Local property in the Properties pane is set to True, you are referencing an autogenerated IA, not the PIA. You should remove this reference and add the correct one. If you correctly reference the Excel 2003 PIA, your Excel reference's Copy Local property will be False and the Path property, on a Windows XP machine, should look something like t