0

这里的错误是“范围是一个变量,但用作一种方法”

我添加了“Microsoft.Office.Interop.Excel”并将其当前用作

Microsoft.Office.Interop.Excel.Workbook SelWorkBook = excelappln1.Workbooks.Open(curfile, 0, false, 5, "", "", false,
Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true,
false, 0, false, false, false);

Microsoft.Office.Interop.Excel.Sheets excelSheets = SelWorkBook.Worksheets;

Microsoft.Office.Interop.Excel.Worksheet excelworksheet = (Microsoft.Office.Interop.Excel.Worksheet)excelSheets.get_Item(CurSheetName);

Microsoft.Office.Interop.Excel.Range excelRange = excelworksheet.UsedRange;

object[,] value;

excelRange = excelworksheet.get_Range(CurTaskNode.DATA_MIN_ROW, CurTaskNode.DATA_MIN_COL);

value = (object[,])excelRange.Cells.Value2;

and using the Value to check the cell is locked or not.... 

if (!value (excelworksheet.Cells[CurTaskNode.DATA_MIN_ROW + minRow, CurTaskNode.DATA_MIN_COL + minCol]).Locked)

{

// Assigning the Value from reader to the particular cell in excel sheet

excelworksheet.Cells[CurTaskNode.DATA_MIN_ROW + minRow, CurTaskNode.DATA_MIN_COL + minCol] = values[iValueIndex];

iValueIndex++;

}

它显示了错误 - 值是一个变量,但用作方法..

请帮我

谢谢

拉姆

4

1 回答 1

2

问题出在这条线上

if (!value (excelworksheet.Cells[CurTaskNode.DATA_MIN_ROW + minRow, CurTaskNode.DATA_MIN_COL + minCol]).Locked)

将其更改为:

if (value == null && !excelworksheet.Cells[CurTaskNode.DATA _MIN _ROW + minRow, CurTaskNode.DATA _MIN _COL + minCol]).Locked)

引发错误是因为您已将 value 声明为二维对象数组,并且在第一行您尝试使用它是一种方法,即 !value(CellRange).Locked

于 2009-07-02T11:49:39.577 回答