首次提交:本地项目同步到Gitea

This commit is contained in:
zhusenlin
2026-01-24 08:45:54 +08:00
commit 4a6b23db69
256 changed files with 25311 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
using ExcelDataReader;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
namespace Io.Github.Kerwinxu.LibShapes.Utils
{
/// <summary>
/// 这个是一个工具类可以读取excel数据的
/// </summary>
public class ExcelData
{
public static DataTable LoadExcel(string file_path)
{
using (var stream = File.Open(file_path, FileMode.Open, FileAccess.Read))
{
using (var reader = ExcelReaderFactory.CreateReader(stream))
{
// Gets or sets a callback to obtain configuration options for a DataTable.
var conf = new ExcelDataSetConfiguration()
{
// Gets or sets a value indicating whether to set the DataColumn.DataType
// property in a second pass.
UseColumnDataType = true,
// Gets or sets a callback to determine whether to include the current sheet
// in the DataSet. Called once per sheet before ConfigureDataTable.
FilterSheet = (tableReader, sheetIndex) => true,
// Gets or sets a callback to obtain configuration options for a DataTable.
ConfigureDataTable = (tableReader) => new ExcelDataTableConfiguration()
{
// Gets or sets a value indicating the prefix of generated column names.
EmptyColumnNamePrefix = "Column",
// Gets or sets a value indicating whether to use a row from the
// data as column names. 是否使用数据作为列名
UseHeaderRow = true,
//// Gets or sets a callback to determine which row is the header row.
//// Only called when UseHeaderRow = true.
//ReadHeaderRow = (rowReader) =>
//{
// // F.ex skip the first row and use the 2nd row as column headers:
// rowReader.Read();
//},
// Gets or sets a callback to determine whether to include the
// current row in the DataTable.
FilterRow = (rowReader) =>
{
return true;
},
// Gets or sets a callback to determine whether to include the specific
// column in the DataTable. Called once per column after reading the
// headers.
FilterColumn = (rowReader, columnIndex) =>
{
return true;
}
}
};
var ds = reader.AsDataSet(conf);
// 这里方便只是导入第一个
return ds.Tables[0];
}
}
return null;
}
}
}