1 /// <summary>读取excel
2 /// 默认第一行为表头
3 /// </summary>
4 /// <param name="strFileName">excel文档绝对路径</param>
5 /// <param name="rowIndex">内容行偏移量,第一行为表头,内容行从第二行开始则为1</param>
6 /// <returns></returns>
7 public static DataTable Import(string strFileName, int rowIndex)
8 {
9 DataTable dt = new DataTable();
10
11 IWorkbook hssfworkbook;
12 using (FileStream file = new FileStream(strFileName, FileMode.Open, FileAccess.Read))
13 {
14 hssfworkbook = WorkbookFactory.Create(file);
15 }
16 ISheet sheet = hssfworkbook.GetSheetAt(0);
17
18 IRow headRow = sheet.GetRow(0);
19 if (headRow != null)
20 {
21 int colCount = headRow.LastCellNum;
22 for (int i = 0; i < colCount; i++)
23 {
--NPOI读取Excel单元格中的公式值
最新推荐文章于 2023-04-03 17:15:39 发布