Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用EPPus cause从Excel文件中读取值;“行超出范围”;错误_C#_.net_Epplus - Fatal编程技术网

C# 使用EPPus cause从Excel文件中读取值;“行超出范围”;错误

C# 使用EPPus cause从Excel文件中读取值;“行超出范围”;错误,c#,.net,epplus,C#,.net,Epplus,我正在使用EPPlus库编写这段代码(只是为了测试) 为了测试我的代码是否工作正常,我添加了这一行textBox3.Text=currentsheet.Cells[0,1].Value.ToString()(我是从中得到这个想法的),但当我执行应用程序时,我会出现以下错误: 行超出范围 为什么呢?我错过了什么或者我做错了什么?这是错误的堆栈跟踪: System.ArgumentException was unhandled HResult=-2147024809 Message=Row

我正在使用EPPlus库编写这段代码(只是为了测试)

为了测试我的代码是否工作正常,我添加了这一行
textBox3.Text=currentsheet.Cells[0,1].Value.ToString()(我是从中得到这个想法的),但当我执行应用程序时,我会出现以下错误:

行超出范围

为什么呢?我错过了什么或者我做错了什么?这是错误的堆栈跟踪:

System.ArgumentException was unhandled   HResult=-2147024809   Message=Row out of range   Source=EPPlus   StackTrace:
       at OfficeOpenXml.ExcelRange.ValidateRowCol(Int32 Row, Int32 Col)
       at OfficeOpenXml.ExcelRange.get_Item(Int32 Row, Int32 Col)
       at WindowsFormsApplication1.ExcelDBUserControl.btnCargarExcel_Click(Object sender, EventArgs e) in d:\Private\Dropbox\Work\ClanMovil21Comunicaciones\Apps\WindowsFormsApplication1\WindowsFormsApplication1\ExcelDBUserControl.cs:line 74
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at WindowsFormsApplication1.Program.Main() in d:\Private\Dropbox\Work\ClanMovil21Comunicaciones\Apps\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 20
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()   InnerException:

另外,与此主题相关的另一个问题(我不知道是否最好只为此提出一个新问题),我如何才能获得每个工作表的名称(文本),然后根据工作簿中的工作表数量生成选项按钮?

Excel工作表中的第一个单元格是[1,1]。currentWorkSheet.Cells[0,1]可能是此异常的原因,Cells[0,1]超出范围

@mcalex我不是C#专家,所以我不明白你的意思,请你解释清楚好吗?“Excel工作表中的第一个单元格是[1,1]”。这就是我需要的。非常感谢。
System.ArgumentException was unhandled   HResult=-2147024809   Message=Row out of range   Source=EPPlus   StackTrace:
       at OfficeOpenXml.ExcelRange.ValidateRowCol(Int32 Row, Int32 Col)
       at OfficeOpenXml.ExcelRange.get_Item(Int32 Row, Int32 Col)
       at WindowsFormsApplication1.ExcelDBUserControl.btnCargarExcel_Click(Object sender, EventArgs e) in d:\Private\Dropbox\Work\ClanMovil21Comunicaciones\Apps\WindowsFormsApplication1\WindowsFormsApplication1\ExcelDBUserControl.cs:line 74
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at WindowsFormsApplication1.Program.Main() in d:\Private\Dropbox\Work\ClanMovil21Comunicaciones\Apps\WindowsFormsApplication1\WindowsFormsApplication1\Program.cs:line 20
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()   InnerException: