0
我正在寫一個基本的程序來使用C#來操縱Excel,而且我在分配範圍時遇到了問題。這裏是我的代碼:分配Excel範圍時出現HRESULT錯誤?
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以前的帖子,你可以查看以及http://stackoverflow.com/questions/891394/excel-error-hresult-0x800a03ec-while-trying-使用單元格名稱來獲取範圍基本上,您希望Excel能夠找到不存在的東西,這種方式與索引超出邊界的方式大致相同...... – MethodMan 2014-10-07 17:06:02