private void ThisAddIn_Startup(object sender, System.EventArgs e) { window = new ExcelWindow(); Application.WorkbookBeforeClose += new Excel.AppEvents_WorkbookBeforeCloseEventHandler(Application_WorkbookBeforeClose); Application.WorkbookActivate += new Excel.AppEvents_WorkbookActivateEventHandler(Application_WorkbookActivate); Application.WorkbookDeactivate += new Excel.AppEvents_WorkbookDeactivateEventHandler(Application_WorkbookDeactivate); }
public override void OnInspectorGUI() { var path = AssetDatabase.GetAssetPath(target); GUI.enabled = true; if (path.EndsWith(".xls") || path.EndsWith(".xlsx")) { if (GUILayout.Button("Export")) { var excelInfo = new ExcelInfo(); excelInfo.SetData(path); ExcelWindow.ExportTable(excelInfo); } } }
public void excelCommand() { const uint OBJID_NATIVEOM = 0xFFFFFFF0; Guid IID_IDispatch = new Guid("{00020400-0000-0000-C000-000000000046}"); myExcelApp = null; ExcelWindow excelWindow = null; try { int hRes = AccessibleObjectFromWindow(handle, OBJID_NATIVEOM, IID_IDispatch.ToByteArray(), out excelWindow); if (hRes >= 0) { myExcelApp = (Application)excelWindow.GetType().InvokeMember("Application", System.Reflection.BindingFlags.GetProperty, null, excelWindow, null); } } catch (Exception e) { Console.WriteLine(e.ToString()); } if (myExcelApp != null) { Console.WriteLine( "Successfully attached to running instance of Excel."); Excel.Worksheet sheet = null; try { Excel.Workbook workbook = myExcelApp.ActiveWorkbook; if (workbook != null) { Console.WriteLine("got workbook"); } //sheet = (Worksheet)workbook.Sheets[1]; sheet = myExcelApp.ActiveSheet; if (sheet != null) { Console.WriteLine("got sheet"); sum(myExcelApp); } } catch (Exception e) { Console.WriteLine(e.ToString()); } } }
//Excel筛选 private void btnExcelFiltarte_Click(object sender, EventArgs e) { if (excelWindow != null) { if (excelWindow.FileName == tbExcelPath.Text && excelWindow.Visible) { excelWindow.Focus( ); return; } else { excelWindow.Close( ); } } excelWindow = new ExcelWindow(tbExcelPath.Text); excelWindow.callback = FinishExcelWindow; excelWindow.ShowDialog( ); }
static extern int AccessibleObjectFromWindow(int hwnd, uint dwObjectID, byte[] riid, out ExcelWindow ptr);
/*您可以像编辑Excel文档一样编辑它,同时您也可以从源成绩单中复制相关数据到本表中, * 填写完毕后请关闭窗口,数据将自动保存.*/ private void sfButton1_Click(object sender, EventArgs e) { //if(Program.ExcelWindow.FileName=="") // Program.ExcelWindow.spreadsheet1.Open("Data\\Test\\c5.xlsx"); //else // Program.ExcelWindow.spreadsheet1.Open(Program.ExcelWindow.FileName); //Program.ExcelWindow.ShowDialog(); //MessageBox.Show($"Temp\\{Program.XlsFile}"); try { File.Copy(@"Data\Test\c5.xlsx", Application.StartupPath + $"\\Temp\\{Program.XlsFile}", true); } catch (Exception) { var dlg = new DialogWindows10(); dlg.title.Text = "应用程序内部错误"; dlg.subtitle.Text = "请检查以下问题是否存在,修复并重试:\r\n" + "1. 应用程序不完整,请重新下载应用程序.\r\n" + "2. 应用程序没有在文件系统上操作文件的权限,请修改权限设置.\r\n" + "3. 如果以上均无问题,请联系应用程序开发者."; return; } var xls = new Process() { StartInfo = { FileName = $"Temp\\{Program.XlsFile}", }, }; xls.Start(); xls.WaitForExit(); ExcelWindow ew = new ExcelWindow("检查数据"); ew.spreadsheet1.Open($"Temp\\{Program.XlsFile}"); MessageBox.Show("单击确定以继续...", WriteObject(ew.spreadsheet1.ActiveSheet)); Log("Loop Begin"); while (ew.Export() == null) { Log("Looping..."); if (ew.Error) { break; } } if (!ew.Error) { var data = ew.Export(); Program.Data.FillExcel = data; MessageBox.Show(JsonConvert.SerializeObject(data[0]), "测试数据"); this.Hide(); var fmt = new FormatWindow(); fmt.FormClosed += (s, args) => this.Close(); fmt.Show(); } else { return; } //Process.Start($"Temp\\{Program.XlsFile}"); }