Late Binding With Excel
-
Hi, Here is the program for displaying simple text in excel using late binding. It checks at run time.This program works on all the version of Excel. I want to modfify this program. Can anybody help me to do that. I want to display All the rows and coulmns of Emp table This is very easy with early binding. I want to do that with late binding here is code Write this code inside button click event pls anybody modify I want to display table conntents Excel using late binding ---------------------------------------- object objApp_Late; object objBook_Late; object objBooks_Late; object objSheets_Late; object objSheet_Late; object objRange_Late; object[] Parameters; int intExcelPID; try { // Get the class type and instantiate Excel. Type objClassType; objClassType = Type.GetTypeFromProgID("Excel.Application"); objApp_Late = Activator.CreateInstance(objClassType); Process[] aProcesses=Process.GetProcessesByName("Excel"); // please remove the string variable string strProc="These are the processes running \n"; for (int i = 0; i <= aProcesses.GetUpperBound(0); i++) { intExcelPID = aProcesses[i].Id; strProc+=intExcelPID.ToString()+ " "; } //Get the workbooks collection. objBooks_Late = objApp_Late.GetType().InvokeMember( "Workbooks", BindingFlags.GetProperty, null, objApp_Late, null ); //Add a new workbook. objBook_Late = objBooks_Late.GetType().InvokeMember( "Add", BindingFlags.InvokeMethod, null, objBooks_Late, null ); //Get the worksheets collection. objSheets_Late = objBook_Late.GetType().InvokeMember( "Worksheets", BindingFlags.GetProperty, null, objBook_Late, null ); //Get the first worksheet. Parameters = new Object[1]; Parameters[0] = 1; objSheet_Late = objSheets_Late.GetType().InvokeMember( "Item", BindingFlags.GetProperty, null, objSheets_Late, Parameters ); //Get a range object that contains cell A1. Parameters = new Object[2]; Parameters[0] = "A1"; Parameters[1] = Missing.Value; objRange_Late = objSheet_Late.GetType().InvokeMember( "Range", BindingFlags.GetProperty, null, objSheet_Late, Parameters ); //Write "Hello, World!" in cell A1. Parameters = new Object[1]; Parameters[0] = "Hello, World!"; objRange_Late.GetType().InvokeMember( "Value", BindingFlags.SetProperty, null, objRange_Late, Parameters ); //Return control of Excel to the user