¡¡¡¡ThisAddIn_StartupʼþÖÐ,³õʼ»¯ËĸöÃæ°å,²¢¶ÔÆä»ù±¾ÊôÐÔ½øÐÐÉèÖÃ,Í£¿¿ÔÚÉϵÄÃæ°åÎÒÉèÖÃÆäHeightÎÞЧ,¸Ä³ÉWidthºóÆäЧ¹ûºÍHeightÔ¤ÆÚµÄÒ»Ñù(²»ÖªµÀÕâ¸öµ×²ã¿ª·¢ÈËÔ±ÊÇÔõôÏëµÄ,¹þ¹þ!)ÁíÍâ Excel._Worksheet ws = (Excel._Worksheet)this.Application.ActiveWorkbook.ActiveSheet;ÊǷdz£¹Ø¼üµÄÒ»¾ä,ÎÒÕâÀï×ã×ãÕÛÌÚÁ˺ܾÃ,ÔÒòÊÇusing Microsoft.Office.Tools.Excel ºÍ using Microsoft.Office.Interop.Excel ¶¼ÓÐworksheetÔªËØ,½á¹¹»ìÏýÁË,ÔËÐÐʱÀÏÊÇ»ñÈ¡²»µ½ExcelµÄActiveWorkbook.
¡¡¡¡4 UCTaskGridÉè¼Æ
¡¡¡¡UCTaskGridÊÇÒ»¸öÓû§¿Ø¼þ,°üº¬Ò»¸ö¹¤¾ßÌõºÍÒ»¸ödataGridView1¿Ø¼þ,ÆäÉè¼Æ½çÃæÈçÏÂ:
¡¡¡¡ºǫ́´úÂëÈçÏÂ:
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Drawing; 5 using System.Data; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; ExcelAddInDemo 11 { 12 using Excel = Microsoft.Office.Interop.Excel; UCTaskGrid : UserControl 14 { 15 public UCTaskGrid() 16 { 17 InitializeComponent(); 18 } UCTaskGrid_Load(object sender, EventArgs e) 21 { System.Data.DataTable dt = SqlHelper.getDateTable(, null); 24 this.dataGridView1.DataSource = dt; 25 } ±£´æSToolStripButton_Click(object sender, EventArgs e) 28 { Excel._Worksheet ws = (Excel._Worksheet)Globals.ThisAddIn.Application.ActiveWorkbook.ActiveSheet; 31 string name = ws.Name; 32 string ID = ((string)(ws.Cells[2, 5] as Excel.Range).Value).ToString(); 33 string First = ((string)(ws.Cells[2, 5] as Excel.Range).Value).ToString(); 34 string Last = ((string)(ws.Cells[3, 3] as Excel.Range).Value).ToString(); 35 string Email = ((string)(ws.Cells[3, 5] as Excel.Range).Value).ToString(); , ID, First, Last, Email); 37 int rows= SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, System.Data.CommandType.Text,sql,null); 38 if (rows == 1) 39 { ); 41 } { ); 45 } 46 47 } ´ò¿ªOToolStripButton_Click(object sender, EventArgs e) 50 { System.Data.DataTable dt = SqlHelper.getDateTable(, null); 53 this.dataGridView1.DataSource = dt; 54 } 55 } 56 }
¡¡¡¡5 Add-InǿǩÃû
¡¡¡¡Í¨¹ýÉèÖóÌÐòµÄÊôÐÔÖеÄÇ©ÃûÒ³,ÈÃVS×Ô¶¯Éú³ÉÒ»¸öÇ©Ãû¼´¿É(ÐèÉèÖÃÃÜÂë)
¡¡¡¡ÎªÁËÖ±¹ÛµÄչʾ,¿´ÏÂÃæµÄ¶¯»:
¡¡¡¡ÏÖÔÚ¹¦ÄܺÜÇ¿´óµÄExcel·þÎñÆ÷,ÆäÖÐÒ»¸öÁÁµã¾ÍÊÇÔÚExcelÖнøÐнçÃæÉè¼ÆºÍÊý¾Ý²Ù×÷,È»ºó¾ÍÊý¾Ý³Ö¾Ã»¯µ½Êý¾Ý¿âÖÐ,ÄÇôÎҵIJÂÏëÊÇ,Äܲ»ÄÜͨ¹ýAddInµÄ·½Ê½ÊµÏÖÒ»¸öexcel service¹¦ÄÜÄØ,½«½çÃæÉè¼ÆÐòÁл¯±£´æµ½Êý¾Ý¿âÖÐ,²¢¸øÒ»¸ö·¾¶(Ψһ),µ«Óû§µ¥»÷²Ëµ¥(È·¶¨ÁË·¾¶)ºó½«½çÃæÉè¼Æ³ÊÏÖµ½excelÖÐ,È»ºóÓû§²Ù×÷Íê³Éºó,ͨ¹ýºǫ́³ÌÐò½«Êý¾Ý¿â±£´æµ½Êý¾Ý¿âÖÐ.
¡¡