Excel导入数据库
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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。