npoi

asp.net 使用NPOI读取excel文件

╄→гoц情女王★ 提交于 2019-12-05 03:50:35
asp.net 使用NPOI读取excel文件内容 NPOI下载地址: NPOI public class ExcelHelper { /// <summary> /// 读取Excel文件数据到DataSet,一个Sheet对应一个DataTable /// </summary> /// <param name="strExcelFilePath">Excel文件的物理路径</param> /// <returns></returns> public static DataSet GetDataFromExcel(string strExcelPhysicalPath, out string strError) { try { DataSet dsResult = new DataSet(); strError = ""; IWorkbook wbook = null; using (FileStream fs = new FileStream(strExcelPhysicalPath, FileMode.Open, FileAccess.Read)) { if (strExcelPhysicalPath.IndexOf(".xlsx") > 0) { wbook = new XSSFWorkbook(fs); } else { wbook = new HSSFWorkbook

C# .NET 使用 NPOI 读取 .xlsx 格式 Excel

…衆ロ難τιáo~ 提交于 2019-12-05 01:54:44
1 string filePath = @"C:\Users\yangqinglin\Desktop\test.xlsx"; 2 IWorkbook wk = null; 3 string extension = System.IO.Path.GetExtension(filePath); 4 FileStream fs = File.OpenRead(filePath); 5 if (extension.Equals(".xls")) 6 { 7 //把xls文件中的数据写入wk中 8 wk = new HSSFWorkbook(fs); 9 } 10 else 11 { 12 //把xlsx文件中的数据写入wk中 13 wk = new XSSFWorkbook(fs); 14 } 15 fs.Close(); 16 17 int sheetCount = wk.NumberOfSheets;//获取sheet的数量 18 ISheet sheet = wk.GetSheetAt(0);//第一个sheet页(列表) 19 int rowCount = sheet.LastRowNum; 20 IRow row = sheet.GetRow(0); //读取当前行数据 21 22 #region 读取第一个sheet页面 23 for (int i = 0; i <=

NPOI DataFormat

不想你离开。 提交于 2019-12-03 14:24:58
I'm exporting a grid with NPOI v1.2.3, and am having trouble getting cell formatting to work. I have a class that exports a list of objects to an XLS file. A row is created for each object, and a cell is added for each configured property. The cell data format can be set on a per-property level. I've read that you shouldn't create a new style for each cell . I can't hard-code my styles, since my exporter needs to support any class. Instead, I wrote a little cache system that only creates a new CellStyle if one hasn't already been created for the current cell's format. Unfortunately, this still

NPOI DataFormat

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm exporting a grid with NPOI v1.2.3, and am having trouble getting cell formatting to work. I have a class that exports a list of objects to an XLS file. A row is created for each object, and a cell is added for each configured property. The cell data format can be set on a per-property level. I've read that you shouldn't create a new style for each cell . I can't hard-code my styles, since my exporter needs to support any class. Instead, I wrote a little cache system that only creates a new CellStyle if one hasn't already been

Using NPOI, how do I return a cell value as it has been formatted by Excel?

匿名 (未验证) 提交于 2019-12-03 01:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Using NPOI , is there any buildin possibility to format a cell value (especially numeric and date values) as it has been formatted by Excel ? If not what would be the best way to implement it? I thought of a formatstring converter from Excel-formatstrings to C#-formatstrings? The following example assumes the Excel-formatstring and the C#-formatstring are the same. So it works for some basic formatstrings like: "#,##0.00" using NPOI.SS.UserModel; ICell cell = workbook.GetSheet("table1").GetRow(0).GetCell(0); string value = null; if(cell

C#中NPOI操作excel之读取和写入excel数据

匿名 (未验证) 提交于 2019-12-03 00:39:02
一、下载引用 下载需要引用的dll,即:NPOI.dll,NPOI.OOXML.dll,NPOI.OpenXml4Net.dll,ICSharpCode.SharpZipLib.dll(office2007版需要此dll)。 二、excel转datatable类 using System; using System.Data; using System.IO; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using NPOI.HSSF.UserModel; namespace NPOIOprateExcel { public class ExcelUtility { /// <summary> /// 将excel导入到datatable /// </summary> /// <param name="filePath"> excel路径 </param> /// <param name="isColumnName"> 第一行是否是列名 </param> /// <returns> 返回datatable </returns> public static DataTable ExcelToDataTable ( string filePath, bool isColumnName ) { DataTable

NPOI导入导出实例

匿名 (未验证) 提交于 2019-12-03 00:34:01
导出: /// <summary> /// Datable导出成Excel /// </summary> /// <param name="dt"></param> /// <param name="file">导出路径(包括文件名与扩展名)</param> public static void TableToExcel(DataTable dt, string file) { IWorkbook workbook; string fileExt = Path.GetExtension(file).ToLower(); if (fileExt == ".xlsx") { workbook = new HSSFWorkbook(); } else if (fileExt == ".xls") { workbook = new HSSFWorkbook(); } else { workbook = null; } if (workbook == null) { return; } ISheet sheet = string.IsNullOrEmpty(dt.TableName) ? workbook.CreateSheet("Sheet1") : workbook.CreateSheet(dt.TableName); //表头 IRow row = sheet.CreateRow(0)

C#使用NPOI读取excel

匿名 (未验证) 提交于 2019-12-03 00:18:01
visual studio使用NuGet安装最新的NPOI(当前为2.3.0) NPOI读写Excel http://www.cnblogs.com/luxiaoxun/p/3374992.html NPOI 中的公式列的值的获取 https://hk.saowen.com/a/e2a742a369cb1ac6722fe417e17cd419ff40342a436df6c700198dbdbeac94d5 公式格类型的判断,下面耗时较长,不要放在for循环里 XSSFFormulaEvaluator evalor0 = null; HSSFFormulaEvaluator evalor1 = null; if (fileName.IndexOf(".xlsx") > 0 || fileName.IndexOf(".xlsm") > 0) // 2007版本 evalor0 = new XSSFFormulaEvaluator(workbook); else evalor1 = new HSSFFormulaEvaluator(workbook); 文章来源: C#使用NPOI读取excel

c# NPOI 方式读取 EXCEL表 类

匿名 (未验证) 提交于 2019-12-03 00:00:02
参考链接:https://www.cnblogs.com/chunxiong/p/9406178.html 稍微修改了一下。。。学习学习!! namespace NPOIClass { public class NPOIC { private static int sheetCellNumMax = 12 ; /// <summary> /// 获取sheet表名 /// </summary> /// <param name="filePath"></param> /// <returns></returns> public static string [] GetSheetName ( string filePath ) { int sheetNumber = 0 ; var file = new FileStream ( filePath , FileMode . Open , FileAccess . Read ); if ( filePath . IndexOf ( ".xlsx" ) > 0 ) { //2007版本 var xssfworkbook = new XSSFWorkbook ( file ); sheetNumber = xssfworkbook . NumberOfSheets ; string [] sheetNames = new string [

NPOI读写

匿名 (未验证) 提交于 2019-12-02 22:06:11
NPOI POI Excel,Word,PPT 文件。 Examples ,    读Excel HSSFWorkbook 类来处理 xls, XSSFWorkbook IWorkbook IWorkbook 来统一处理 xls 和 xlsx 格式的文件 public void ReadFromExcelFile(string filePath) { IWorkbook wk = null; string extension = System.IO.Path.GetExtension(filePath); try { FileStream fs = File.OpenRead(filePath); if (extension.Equals(".xls")) { //把xls文件中的数据写入wk中 wk = new HSSFWorkbook(fs); } else { //把xlsx文件中的数据写入wk中 wk = new XSSFWorkbook(fs); } fs.Close(); //读取当前表数据 ISheet sheet = wk.GetSheetAt(0); IRow row = sheet.GetRow(0); //读取当前行数据 //LastRowNum 是当前表的总行数-1(注意) int offset = 0; for (int i = 0; i <= sheet