المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Excel with Early and LateBinding



C# Programming
04-02-2009, 04:51 PM
Hi Guys. I have a slight problem. My application usses EarlyBinding.where I reference Excel 12. Problem I'm having is that most of the machines targeted have Excel 10 or Excel 11 installed so when installing the App or running it I get a GAC error. This I know is that the versions are not backward compatable. My question is, how do I go from earlybinding to LateBinding with as little changes possible. Below I instanciate my Excel Workbook etc. My code is doing loads of stuff and I wouldn't want to rewrite all of it.

Microsoft.Office.Interop.Excel.Application objExcel =
new Microsoft.Office.Interop.Excel.Application();
objExcel.Visible = false;
Microsoft.Office.Interop.Excel.Workbook objBook =
objExcel.Workbooks.Add(System.Reflection.Missing.Value);
Microsoft.Office.Interop.Excel.Worksheet objSheet =
(Microsoft.Office.Interop.Excel.Worksheet)
objBook.Worksheets.get_Item(1);
Microsoft.Office.Interop.Excel.Range objRange;

Any advice would be appreciated.

Excellence is doing ordinary things extraordinarily well.