HTML5技术

C#如何定制Excel界面并实现与数据库交互 - JackWang-CUMT(2)

字号+ 作者:H5之家 来源:博客园 2015-11-26 09:21 我要评论( )

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Xml.Linq; 6 using Excel = Microsoft.Office.Interop.Excel; 7 namespace ExcelAddInDemo 8 { 9

1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Xml.Linq; 6 using Excel = Microsoft.Office.Interop.Excel; 7 namespace ExcelAddInDemo 8 { 9 using Microsoft.Office.Tools; ThisAddIn 11 { 12 public CustomTaskPane _MyCustomTaskPane = null; ThisAddIn_Startup(object sender, System.EventArgs e) 15 { 16 UCTaskPane taskPane = new UCTaskPane(); ); _MyCustomTaskPane.Visible = true; 20 _MyCustomTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionTop; 21 22 UCPaneLeft panLeft = new UCPaneLeft(); ); 24 _MyCustomTaskPane.Width = 200; 25 _MyCustomTaskPane.Visible = true; 26 _MyCustomTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionLeft; 27 28 UCTaskGrid panRight = new UCTaskGrid(); ); 30 _MyCustomTaskPane.Width = 200; 31 _MyCustomTaskPane.Visible = true; 32 _MyCustomTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight; 33 34 UCLog panLog = new UCLog(); ); 36 _MyCustomTaskPane.Width = 60; 37 _MyCustomTaskPane.Visible = true; 38 _MyCustomTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionBottom; Hook into the workbook open event .Application.WorkbookActivate += Application_WorkbookActivate; 43 //test } Application_SheetSelectionChange(object Sh, Excel.Range Target) 48 { 49 if (this.Application != null) 50 { 51 this.Application.Caption = this.Application.ActiveCell.Address.ToString();//$A$1 $A$1 } 56 } Application_WorkbookActivate(Excel.Workbook Wb) 59 { 60 //using Microsoft.Office.Tools.Excel 和 using Microsoft.Office.Interop.Excel 都有worksheet等,容易混淆 Excel._Worksheet ws = (Excel._Worksheet)this.Application.ActiveWorkbook.ActiveSheet; ; r=2,c=2; ((Excel.Range)ws.Cells[r, c]).Value2 = ; 68 ((Excel.Range)ws.Cells[r, c]).Interior.Color =System.Drawing. ColorTranslator.ToOle(System.Drawing.Color.Red); ((Excel.Range)ws.Cells[r, c]).Style.Font.Bold = true; format , )).Font.Bold = true; , )).Font.Italic = true; , )).Font.Color = System.Drawing.Color.FromArgb(96, 32, 0).ToArgb(); , )).Font.Name = ; , )).Font.Size = 15; Excel.Range range = ((Microsoft.Office.Interop.Excel.Range)ws.get_Range(, )); 81 Excel. Borders border = range.Borders; 82 border[Excel.XlBordersIndex.xlEdgeBottom].LineStyle =Excel. XlLineStyle.xlContinuous; 83 border.Weight = 2d; 84 border[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Excel.XlLineStyle.xlContinuous; 85 border[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Excel.XlLineStyle.xlContinuous; 86 border[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Excel.XlLineStyle.xlContinuous; ws.Cells[; ; ; 91 } ThisAddIn_Shutdown(object sender, System.EventArgs e) 93 { 94 } VSTO 生成的代码 设计器支持所需的方法 - 不要 100 /// 使用代码编辑器修改此方法的内容。 InternalStartup() 103 { 104 this.Startup += new System.EventHandler(ThisAddIn_Startup); 105 this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); 106 } } 110 }

 

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 如何快速处理线上故障 - 倒骑的驴

    如何快速处理线上故障 - 倒骑的驴

    2017-05-02 12:01

  • Dora.Interception: 一个为.NET Core度身定制的AOP框架 - Artech

    Dora.Interception: 一个为.NET Core度身定制的AOP框架 - Artech

    2017-05-02 11:00

  • 如何在 ASP.NET Core 中发送邮件 - Savorboard

    如何在 ASP.NET Core 中发送邮件 - Savorboard

    2017-05-02 08:02

  • 对于Bootstrap的介绍以及如何使用 - novai-L

    对于Bootstrap的介绍以及如何使用 - novai-L

    2017-04-29 09:00

网友点评
(