为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

npoi读取exc

2017-09-25 4页 doc 15KB 76阅读

用户头像

is_841159

暂无简介

举报
npoi读取excnpoi读取exc //configÖÐÅäÖõÄÉÏ??µÄExcelÂ??? static object basePath = ConfigurationManager.AppSettings["FilePath"]; #region ?ÁÈ?ExcelÎÄ?þ /// /// ?ÁÈ?ExcelÎÄ?þµ?tableÖÐ /// /// excelÎÄ?þÂ??? /// public static DataTable ReadExcel(string fileName) { DataTa...
npoi读取exc
npoi读取exc //configÖÐÅäÖõÄÉÏ??µÄExcelÂ??? static object basePath = ConfigurationManager.AppSettings["FilePath"]; #region ?ÁÈ?ExcelÎÄ?þ /// /// ?ÁÈ?ExcelÎÄ?þµ?tableÖÐ /// /// excelÎÄ?þÂ??? /// public static DataTable ReadExcel(string fileName) { DataTable dt = new DataTable(); string filePath = ""; if (basePath != null) { filePath = HostingEnvironment.MapPath((basePath.ToString() + fileName)); dt = ImportExcelFile(filePath); } //ÎÄ?þÊÇ?ñ?æÔÚ if (System.IO.File.Exists(filePath)) { } return dt; } public static DataTable ImportExcelFile(string filePath) { HSSFWorkbook hssfworkbook; #region//?õÊ???ÐÅÏ? try { using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { hssfworkbook = new HSSFWorkbook(file); } } catch (Exception e) { throw e; } #endregion NPOI.SS.UserModel.ISheet sheet = hssfworkbook.GetSheetAt(0); System.Collections.IEnumerator rows = sheet.GetRowEnumerator(); DataTable dt = new DataTable(); rows.MoveNext(); HSSFRow row = (HSSFRow)rows.Current; for (int j = 0; j < (sheet.GetRow(0).LastCellNum); j++) { //dt.Columns.Add(Convert.ToChar(((int)'A') + j).ToString()); //??µÚÒ?ÁÐ×?ΪÁÐ?íÍ? dt.Columns.Add(row.GetCell(j).ToString ()); } while (rows.MoveNext()) { row = (HSSFRow)rows.Current; DataRow dr = dt.NewRow(); for (int i = 0; i < row.LastCellNum; i++) { NPOI.SS.UserModel.ICell cell = row.GetCell(i); if (cell == null) { dr[i] = null; } else { dr[i] = cell.ToString(); } } dt.Rows.Add(dr); } return dt; } #endregion
/
本文档为【npoi读取exc】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索