System.ArgumentOutOfRangeException未处理 [英] System.ArgumentOutOfRangeException was unhandled
问题描述
我收到以下错误消息
System.ArgumentOutOfRangeException未处理 消息="索引超出范围。使用ExcelWorkSheet时,必须是非负数且小于集合的大小
我正在编写以下代码snippit
public
void Using_Excle_File( string fileName, int
workSheetIndex, int row,
int 列,
对象 值)
{
ExcelFile excelFile =
新
ExcelFile ();
ExcelWorksheet ws = excelFile.Worksheets [workSheetIndex];
ws.Cells [row,column] .Value = value;
excelFile.SaveXls(fileName);
//它将在以下位置创建:StartWindow \BIN \Debug
}
我该怎么做。
非常感谢
Aya
< blockquote>
您好,
您可能希望在"ExcelWorksheep WS = ..."行停止调试器,并仔细查看excelFile.Worksheets和workSheetIndex。
我只是猜测使用的索引超出了范围。所以在除外离子消息:它不能小于零,它必须小于数组的大小。只需检查两个(easierst调试代码)然后你就知道了。
亲切的问候,
Konrad
I have got the following error message
System.ArgumentOutOfRangeException was unhandled Message="Index was out of range. Must be non-negative and less than the size of the collection
when using the ExcelWorkSheet
I am writing the following code snippit
public
void Using_Excle_File(string fileName,int workSheetIndex,int row, int column, Object value){
ExcelFile excelFile = new ExcelFile();
ExcelWorksheet ws = excelFile.Worksheets[workSheetIndex];
ws.Cells[row,column].Value = value;
excelFile.SaveXls(fileName);
// it will be created in : StartWindow\BIN\Debug}
what can I do.
Thanks so much
Aya
Hi,
maybe you want to stop the debugger at the line "ExcelWorksheep WS = ..." and have a closer look at excelFile.Worksheets and workSheetIndex.
I would simply guess that the index used is out of range. So as given in the exception message: It cannot be less than zero and it must be less that the size of the array. Just check both (easierst with debugging the code) and then you know it for sure.
With kind regards,
Konrad
这篇关于System.ArgumentOutOfRangeException未处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!