读取单元的值,并用对话框

本文介绍如何使用Visual Studio Tools for Office (VSTO)创建Excel插件,包括打开工作表、获取活动单元格及其值,并显示单元格文本。通过示例代码展示了与Excel对象模型交互的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
//-----< using >-----------
using Microsoft.Office.Tools.Ribbon;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Excel;
//----</ using >------------

namespace ExcelAddIn5
{
    public partial class Ribbon1
    {
        private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
        {

        }

        private void button1_Click(object sender, RibbonControlEventArgs e)
        {
            //< open Excel Worksheet >
            Excel.Worksheet activeWorksheet = Globals.ThisAddIn.Application.ActiveSheet;
            //< open Excel Worksheet >

            //< get Cell.Value >
            Excel.Range actCell = Globals.ThisAddIn.Application.ActiveCell;
            if (actCell.Value2 != null)
            {
                string sValue = actCell.Value2.ToString();
                string sText = actCell.Text;
                System.Windows.Forms.MessageBox.Show(sText);
            }
            //</ get Cell Value >
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值