static void Main(string[] args) { Application MyExcel = new ApplicationClass(); Workbook MyWorkbook = MyExcel.Workbooks.Add(Missing.Value); MyWorkbook.Windows.get_Item(1).Caption = "Using Delegates"; Worksheet MyWorksheet1 = (Worksheet)MyWorkbook.Worksheets.get_Item(1); Worksheet MyWorksheet2 = (Worksheet)MyWorkbook.Worksheets.get_Item(2); Worksheet MyWorksheet3 = (Worksheet)MyWorkbook.Worksheets.get_Item(3); MyWorksheet1.Activate(); //Add Event Handler for the BeforeClose Event Event_BeforeBookClose = new AppEvents_WorkbookBeforeCloseEventHandler(BeforeBookClose); MyExcel.WorkbookBeforeClose += Event_BeforeBookClose; //Add Event Handler for the change Event Event_ChangeEvent = new DocEvents_ChangeEventHandler(CellChange); MyWorksheet1.Change += Event_ChangeEvent; MyWorksheet2.Change += Event_ChangeEvent; MyWorksheet3.Change += Event_ChangeEvent; MyExcel.Visible = true; MyExcel.UserControl = true; }
public void addEventsToExcelSheet(Worksheet excelSheet) { //add event link click (OptionSet) FollowHyperlinkEventHandlerDelegate = new DocEvents_FollowHyperlinkEventHandler(FollowHyperlinkEventHandler); excelSheet.FollowHyperlink += FollowHyperlinkEventHandlerDelegate; //event activate sheet ActivateSheetEventDelegate = new DocEvents_ActivateEventHandler(ActivateSheetEvent); ((DocEvents_Event)excelSheet).Activate += ActivateSheetEventDelegate; ChangeEventDelegate = new DocEvents_ChangeEventHandler(ChangeCellEventHandler); excelSheet.Change += ChangeEventDelegate; }
public void Application_WorkbookOpen(Workbook Doc) { Sheets sheets = Doc.Worksheets; connections con = new connections(); funcionesEspeciales fe = new funcionesEspeciales(); foreach (Worksheet sheet in sheets) { if (fe.ReadProperty("conexionSeleccionada", sheet.CustomProperties) != null) { DocEvents_ChangeEventHandler EventDel_CellsChange = new DocEvents_ChangeEventHandler(con.WorksheetChangeEventHandler); sheet.Change += EventDel_CellsChange; } } }
public void Open(DocEvents_ChangeEventHandler ChangeEventHandler) { _workBook = _excelApp.Workbooks.Add(true); _workSheet = (Worksheet)_workBook.ActiveSheet; _workSheet.Change += ChangeEventHandler; }
static void Init() { Microsoft.Office.Interop.Excel._Workbook workbook = null; DocEvents_ChangeEventHandler worksheetChangeHandler = null; try { // Start Excel and get Application object. Excel = new Microsoft.Office.Interop.Excel.Application(); Excel.Visible = false; // Get a new workbook. workbook = (Microsoft.Office.Interop.Excel._Workbook) (Excel.Workbooks.Add(Missing.Value)); // Get the active worksheet Worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.ActiveSheet; // Instantiate a change handler worksheetChangeHandler = new DocEvents_ChangeEventHandler(CellChange); // Add the change handler to the worksheet Worksheet.Change += worksheetChangeHandler; } catch (Exception theException) { String errorMessage; errorMessage = "Error: "; errorMessage = String.Concat(errorMessage, theException.Message); errorMessage = String.Concat(errorMessage, " Line: "); errorMessage = String.Concat(errorMessage, theException.Source); Console.WriteLine(errorMessage); } }