using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Configuration; using System.Data.SqlClient; using System.IO; using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System.Data; if (FileUpload1.HasFile)//判断是否包含文件 { ImportExcel(FileUpload1.FileBytes); }
public void ImportExcel(byte[] b) { System.IO.MemoryStream ms = new MemoryStream(b); HSSFWorkbook workbook = new HSSFWorkbook(ms); ISheet sheet = workbook.GetSheet(workbook.GetSheetName(0)); for (int i = 1; i <= sheet.LastRowNum; i++)//遍历行 { string str = ""; for (int j = 0; j < sheet.GetRow(i).LastCellNum; j++)//遍历列 { str += sheet.GetRow(i).GetCell(j).ToString() + ","; } str = str.Substring(0, str.Length - 1);// //=========================添加数据库====================== //========================================================= } }
*类库去我的下载里面下载
本文出自 “程序猿的家” 博客,请务必保留此出处http://962410314.blog.51cto.com/7563109/1540296
原文:http://962410314.blog.51cto.com/7563109/1540296