|
本帖最后由 faunus 于 2014-2-26 11:02 编辑
先上代码:
- private void ThisAddIn_Startup(object sender, System.EventArgs e)
- {
- //Application 的三种调用形式
- Excel.Application app;
- app = Application;
- app = this.Application;
- app = Globals.ThisAddIn.Application;//在RIBBON中,只能这样调用。
- //获得基本对像
- Excel.Workbook book = app.ActiveWorkbook;
- Excel.Worksheet sh = book.ActiveSheet;
- //单元格对像
- Excel.Range rA1 = sh.Cells[1, 1];
- //开始随便撸
- rA1.Value = "hello";
- rA1.Formula = "=1+100";
- //如何获得对像的真实类型
- string typeA = rA1.GetType().ToString();
- string typeB = Microsoft.VisualBasic.Information.TypeName(rA1);
- System.Windows.Forms.MessageBox.Show
- (
- string.Format(
- "TypeA:{0},TypeB:{1}",
- typeA,
- typeB)
- );
- }
复制代码
|
|