我在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;
}
}
}
现在我在语法上没有任何错误,但是在执行过程中,我的错误率低于rror:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: ''System.__ComObject' does not contain a definition for 'ActiveCell''
在行中:
excelApp.ActiveCell.FormulaR1C1 = "=MIN(C[-14])";
有人请帮我解决这个问题。
您需要FormulaR1C1
直接从特定单元格进行设置
excelApp.Range["P2"].FormulaR1C1 = "=MIN(C[-14])";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句