【发布时间】:2021-04-21 18:19:58
【问题描述】:
我在 excel 中创建 VSTO,为此我将现有的宏转换为 c# 必须找到列的最小值,我已将其转换为如下所示:
using Microsoft.Office.Tools.Ribbon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Excel;
using Microsoft.Office.Interop.Excel;
namespace CpCpk
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
var excelApp = Globals.ThisAddIn.Application.ActiveSheet;
//excelApp.Workbooks.Add();
excelApp.Range["P2"].Select();
excelApp.ActiveCell.FormulaR1C1 = "=MIN(C[-14])";
excelApp.Range["Q2"].Select();
excelApp.Visible = true;
}
}
}
现在我没有收到任何语法错误,但在执行过程中我遇到了错误:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''System.__ComObject' does not contain a definition for 'ActiveCell''
在行中:
excelApp.ActiveCell.FormulaR1C1 = "=MIN(C[-14])";
请有人帮我解决这个问题..
【问题讨论】:
-
试试 excelApp.Range["P2"].FormulaR1C1 = "=MIN(C[-14])";
-
还有@matmahnke,请将您的评论更改为答案,以便我可以标记相同
-
对不起,我对excel一无所知
标签: c# excel vba visual-studio vsto