C# Microsoft.Office.Interop.Excel.SpreadsheetGear不包含活动单元格的定义,也不包含活动单元格的扩展方法

C# Microsoft.Office.Interop.Excel.SpreadsheetGear不包含活动单元格的定义,也不包含活动单元格的扩展方法,c#,com-interop,excel-interop,spreadsheetgear,C#,Com Interop,Excel Interop,Spreadsheetgear,当我想从AxMicrosoft.Office.Interop.Owc11更改为Microsoft.Office.Interop.Excel,从AxSpreadsheet currentSpreadSheet=GetTestSheet更改为Spreadsheet Gear IWorkbook=GetWorkbook时,会出现此错误 “Microsoft.Office.Interop.Excel.SpreadsheetGear”不包含“ActiveCell”的定义,并且找不到接受类型为“Micros

当我想从AxMicrosoft.Office.Interop.Owc11更改为Microsoft.Office.Interop.Excel,从AxSpreadsheet currentSpreadSheet=GetTestSheet更改为Spreadsheet Gear IWorkbook=GetWorkbook时,会出现此错误

“Microsoft.Office.Interop.Excel.SpreadsheetGear”不包含“ActiveCell”的定义,并且找不到接受类型为“Microsoft.Office.Interop.Excel.SpreadsheetGear”的第一个参数的扩展方法“ActiveCell”。是否缺少using指令或程序集引用

ActiveCell上有一个错误

Object searchRange = IWorkbook.ActiveCell.Cells[1, 1];

似乎您想使用电子表格工具而不是Microsoft.Office.Interop.Excel,它们是不同的程序集。SpreadsheetGear是第三方库,Microsoft.Office.Interop.Excel随.net提供。 错误会告诉您问题出在哪里:

Microsoft.Office.Interop.Excel.SpreadsheetGear'不包含 “ActiveCell”的定义

Object searchRange = IWorkbook.ActiveCell.Cells[1, 1];
ActiveCell是SpreadsheetGear命名空间中IWorksheetWindowInfo接口的属性。ActiveCell是当前选择中的单个活动单元格。 我想你应该读一下表格中第一个单元格的使用范围。首先,您应该参考以下内容:

using SpreadsheetGear;
代码如下:

  //this line will create  a new workbook
  IWorkbook workbook = Factory.GetWorkbook();
  IWorksheet worksheet = workbook.ActiveWorksheet;
  //this line represent first cell in used range cells
  SpreadsheetGear.IRange firstCell = worksheet.UsedRange.Cells["A1"];

您想使用SpreadsheetGear.dll还是Microsoft.Office.Interop.Excel dll?SpreadsheetGear.dll,我认为SpreadsheetGear.dll与Microsoft.Office.Interop.Excel一起使用。我是第一次这样做。您可以指导我如何进行以下操作吗?使用SpreadsheetGear.dll而不是Excel=Microsoft.Office.Interop.Excel;,其参考是什么;?