using System.Collections.Generic;
using Excel = Microsoft.Office.Interop.Excel;
namespace TableMagic
{
public partial class ThisAddIn
{
public static class Global
{
public static int readFile;
public static int spotlight;
public static int spotlightColorIndex;
public static Dictionary<string, int> cellColor = new Dictionary<string, int>();
public static bool created_qr_sheet = false;
public static Dictionary<string, int> GetColorDictionary(Excel.Range usedRange)
{
Dictionary<string, int> cellColorDict = new Dictionary<string, int>();
foreach (Excel.Range cell in usedRange)
{
if (cell.Interior.ColorIndex > 0)
{
string cellAddress = cell.Address;
int cellColorIndex = cell.Interior.ColorIndex;
cellColorDict.Add(cellAddress, cellColorIndex);
}
}
return cellColorDict;
}
}
public static Excel.Application app;
public static string hotKey;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
app = Globals.ThisAddIn.Application;
Global.spotlight = 0;
app.SheetSelectionChange += app_SheetSelectionChange;
app.SheetBeforeDelete += new Excel.AppEvents_SheetBeforeDeleteEventHandler(Application_SheetBeforeDelete);
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO 生成的代码
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
private void app_SheetSelectionChange(object sh, Excel.Range Target)
{
if (Global.spotlight == 1)
{
Excel.Range selectedRange = Target;
Excel.Worksheet activesheet = ThisAddIn.app.ActiveSheet;
if (selectedRange.Count != 1)
{
return;
}
else
{
activesheet.Cells.Interior.ColorIndex = 0;
ThisAddIn.app.ScreenUpdating = false;
selectedRange.EntireRow.Interior.ColorIndex = Global.spotlightColorIndex;
selectedRange.EntireColumn.Interior.ColorIndex = Global.spotlightColorIndex;
ThisAddIn.app.ScreenUpdating = true;
}
}
}
private void Application_SheetBeforeDelete(object Sh)
{
Excel.Workbook wb = Globals.ThisAddIn.Application.ActiveWorkbook;
Excel.Worksheet ws = Globals.ThisAddIn.Application.ActiveSheet;
if (ws.Name == "_rename")
{
Global.readFile = 0;
}
if (ws.Name == "_QR_Scan")
{
Global.created_qr_sheet = false;
}
}
}
}