提交代码

This commit is contained in:
2023-12-20 15:48:05 +08:00
parent 2516cfbe69
commit f49eba5e5f
58 changed files with 8868 additions and 1411 deletions
+7 -5
View File
@@ -93,7 +93,7 @@ namespace BLL
/// <param name="strMsg"></param>
/// <param firstTitle="strMsg">第一行是否为表头</param>
/// <returns></returns>
public static DataSet ExcelToDataSet(string filePath, out string strMsg, bool firstTitle = false)
public static DataSet ExcelToDataSet(string filePath, out string strMsg, bool firstTitle = false, bool firstSheet = true)
{
strMsg = "";
DataSet ds = new DataSet();
@@ -108,9 +108,9 @@ namespace BLL
if (fileType == ".xlsx")
{
// 2007版本
fs.Position = 0;
//fs.Position = 0;
XSSFWorkbook workbook = new XSSFWorkbook(fs);
sheetNumber = workbook.NumberOfSheets;
sheetNumber = firstSheet ? 1 : workbook.NumberOfSheets;
for (int i = 0; i < sheetNumber; i++)
{
string sheetName = workbook.GetSheetName(i);
@@ -134,14 +134,13 @@ namespace BLL
{
// 2003版本
HSSFWorkbook workbook = new HSSFWorkbook(fs);
sheetNumber = workbook.NumberOfSheets;
sheetNumber = firstSheet ? 1 : workbook.NumberOfSheets;
for (int i = 0; i < sheetNumber; i++)
{
string sheetName = workbook.GetSheetName(i);
sheet = workbook.GetSheet(sheetName);
if (sheet != null)
{
//dt = GetSheetDataTable(sheet, out strMsg);
dt = firstTitle ? GetFirstSheetDataTable(sheet, out strMsg) : GetSheetDataTable(sheet, out strMsg);
if (dt != null)
{
@@ -179,6 +178,7 @@ namespace BLL
//最大列数
int cellCount = 0;
IRow maxRow = sheet.GetRow(0);
if (maxRow == null) return dt;
for (int i = startIndex; i <= lastIndex; i++)
{
IRow row = sheet.GetRow(i);
@@ -205,6 +205,7 @@ namespace BLL
for (int i = startIndex; i <= lastIndex; i++)
{
IRow row = sheet.GetRow(i);
if (row == null) continue;
//移除空行
if (row.Cells.Count(p => !string.IsNullOrWhiteSpace(p.ToString())) == 0) continue;
DataRow drNew = dt.NewRow();
@@ -300,6 +301,7 @@ namespace BLL
{
IRow row = sheet.GetRow(i);
DataRow dataRow = dt.NewRow();
if (row == null) continue;
//移除空行
if (row.Cells.Count(p => !string.IsNullOrWhiteSpace(p.ToString())) == 0) continue;