首页 > 其他 > 详细

在页面完成读取EXCEL

时间:2016-08-30 17:25:03      阅读:188      评论:0      收藏:0      [点我收藏+]

protected void btnUpload_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string sFILENAME = string.Empty;
string sFILE_EXT = string.Empty;
string sFILE_MIME_TYPE = string.Empty;
HttpPostedFile pstIMPORT = fileIMPORT.PostedFile;
if (pstIMPORT != null)
{
if (pstIMPORT.FileName.Length > 0)
{
sFILENAME = Path.GetFileName(pstIMPORT.FileName);
sFILE_EXT = Path.GetExtension(sFILENAME);
sFILE_MIME_TYPE = pstIMPORT.ContentType;
}
if (sFILE_EXT.ToLower() != ".xls")
{
lblError.Text = "The file format is incorrect, please select excel 2003 format file.";
return;
}
ExcelDataReader.ExcelDataReader spreadsheet = new ExcelDataReader.ExcelDataReader(pstIMPORT.InputStream);
if (spreadsheet.WorkbookData.Tables.Count > 0)
{
dt = spreadsheet.WorkbookData.Tables[0];
GridView1.DataSource = dt;
GridView1.DataBind();
if (dt != null && dt.Rows.Count > 0)
{
lblError.Text = "Data read successfully";
}
}
}
}
}

在页面完成读取EXCEL

原文:http://www.cnblogs.com/it-xcn/p/5822364.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!