private void btn_light_Click(object sender, RibbonControlEventArgs e) { if (btn_light.Checked) { ApplicationChange(Globals.ThisAddIn.Application.ActiveSheet , Globals.ThisAddIn.Application.Selection); Globals.ThisAddIn.Application.SheetSelectionChange += ApplicationChange; } else { if (format != null) { format.Delete(); format = null; } Globals.ThisAddIn.Application.SheetSelectionChange -= ApplicationChange; } }
private void ResetFormatConditionsHighlight(Worksheet worksheet) { if (worksheet != null) { app.ScreenUpdating = false; var isSaved = worksheet.Parent.Saved; int count = worksheet.Cells.FormatConditions.Count; for (int i = count; i >= 1; i--) { try { FormatCondition formatCondition = worksheet.Cells.FormatConditions.Item(i); if (formatCondition.Formula1 == "=CELL(\"row\")=ROW()") { formatCondition.Delete(); } else if (formatCondition.Formula1 == "=AND(CELL(\"row\")=ROW(),CELL(\"col\")=COLUMN())") { formatCondition.Delete(); } } catch (Exception) { // ignored } } if (SettingsCsv.Default.EnableSelectHighlight) { FormatCondition formatCondition2 = worksheet.Cells.FormatConditions.Add(XlFormatConditionType.xlExpression, null, "=AND(CELL(\"row\")=ROW(),CELL(\"col\")=COLUMN())"); formatCondition2.Interior.ColorIndex = 40; FormatCondition formatCondition = worksheet.Cells.FormatConditions.Add(XlFormatConditionType.xlExpression, null, "=CELL(\"row\")=ROW()"); formatCondition.Interior.ColorIndex = 37; } worksheet.Parent.Saved = isSaved; app.ScreenUpdating = true; } }