【发布时间】:2014-10-08 01:05:47
【问题描述】:
我正在编写一个使用 C# 操作 Excel 的基本程序,但在分配范围时遇到了麻烦。这是我的代码:
using Excel = Microsoft.Office.Interop.Excel;
//...various other using statements
static void Main(string[] args)
{
Excel.Application xlApp = new Excel.Application();
xlApp.Visible = true;
Excel.Workbook bk=xlApp.Workbooks.Add();
Excel.Worksheet sht = bk.Sheets["Sheet1"];
Excel.Range rng;
for (int c = 0; c < 10;c++ )
{
rng=sht.Cells[c,1];
rng.Value= "aaa";
}
}
我在rng=sht.Cells[c,1]; 行上不断收到以下错误:
An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Exception from HRESULT: 0x800A03EC
【问题讨论】:
-
尝试用谷歌搜索该异常这里是一个 SO 以前的帖子,您也可以查看 stackoverflow.com/questions/891394/…\
Basically you are expecting Excel to find something that does not Exist与 Index out of Bounds 或多或少相同...
标签: c# excel office-interop