source/Repid.Utility/Helper/NpoiHelper.cs
(开头部分) 11KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
using CsvHelper;
using NPOI.HSSF.UserModel;
using NPOI.SS.Formula.Eval;
using NPOI.SS.UserModel;
using NPOI.SS.Util;
using System;
using System.Collections.Generic;
using System.Data;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
namespace Repid.Utility.Helper
{
/// <summary>
/// Nopi电子表格处理
/// </summary>
public static class NpoiHelper
{
#region Xls
public static DataTable XlsToDataTable(string filePath, int sheetIndex)
{
string extName = Path.GetExtension(filePath);
DataTable dt = new DataTable();
if (extName.Equals(".xls") || extName.Equals(".xlsx"))
{
using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
HSSFWorkbook workbook = new HSSFWorkbook(file);
ISheet sheet = workbook.GetSheetAt(sheetIndex);
//列头
foreach (ICell item in sheet.GetRow(sheet.FirstRowNum).Cells)
{
dt.Columns.Add(item.ToString(), typeof(string));
}
//写入内容
System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
while (rows.MoveNext())
{
IRow row = (HSSFRow)rows.Current;
if (row.RowNum == sheet.FirstRowNum)
{
continue;
}
DataRow dr = dt.NewRow();
foreach (ICell item in row.Cells)
{
后面还有 238 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。