易创云论坛

 找回密码
 立即注册
查看: 3390|回复: 0

VSTO Excel 五种赋值方法

[复制链接]

170

主题

178

帖子

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
100700
发表于 2020-2-12 13:51:24 | 显示全部楼层 |阅读模式
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Office.Tools.Ribbon;
  6. using Microsoft.Office.Interop.Excel;
  7. using Microsoft.Office.Tools.Excel;

  8. namespace Ecell
  9. {
  10.     public partial class Emenu
  11.     {
  12.         private void Emenu_Load(object sender, RibbonUIEventArgs e)
  13.         {

  14.         }

  15.         private void button1_Click(object sender, RibbonControlEventArgs e)
  16.         {

  17.             Application app = Globals.ThisAddIn.Application;

  18.             Microsoft.Office.Interop.Excel.Workbook book = app.ActiveWorkbook;
  19.             Microsoft.Office.Interop.Excel.Worksheet sh = book.ActiveSheet;

  20.             Range rg = sh.get_Range("C3:E7");
  21.             rg.Value = "aaaa";

  22.             rg = sh.get_Range("A2,B2");
  23.             rg.Value = "aaaa";

  24.             sh.Cells[1, 1] = "aaaa";
  25.             
  26.             sh.Range["C3:E7"].Value = "hello range";

  27.             Globals.ThisAddIn.Application.Range["C8:E11"].Value = "bbbb";
  28.         }
  29.     }
  30. }
复制代码



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|易创云论坛 ( 吉ICP备17001024号-1 )

GMT+8, 2025-2-1 21:57 , Processed in 0.269869 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表