asp.net 调用myxls 组件读取excel 工作页出错,请帮助解决!
@信心 2013-12-18 03:00:19
asp.net 调用myxls 组件读取excel 文件工作页出错,提示出错!
异常详细信息: System.IndexOutOfRangeException: sheet1
---------------------------------------------------------------------------------
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using org.in2bits.MyXls;//首先导入命名空间
protected void btnImport_Click(object sender, EventArgs e)
{
//加载要导入的Excel
Label1.Text = filePath;
XlsDocument xls = new XlsDocument();//加载外部Excel
xls.FileName = FileUpload1.FileName;
//获得Excel中的指定一个工作页
Worksheet sheet = xls.Workbook.Worksheets["Sheet1"];
//读取数据 循环每sheet工作页的每一行,不读取前两行
for (int i = 3; i < sheet.Rows.Count; i++)
{
//sheet.Rows[ushort.Parse(i.ToString())].GetCell(1).Value
//解释:获得指定工作页行集合的指定行的指定列的值
Response.Write(sheet.Rows[ushort.Parse(i.ToString())].GetCell(1).Value);
Response.Write("<br/>");
}
}