var path = @"D:\Import_WIP_Example.xlsx"; usingvar doc = SpreadsheetDocument.Open(path, false); var workbookPart = doc.WorkbookPart; var sheet = workbookPart.Workbook.Sheets.GetFirstChild<Sheet>(); var worksheet = ((WorksheetPart)workbookPart.GetPartById(sheet.Id)).Worksheet; var sheetData = worksheet.GetFirstChild<SheetData>(); var sharedTable = workbookPart.SharedStringTablePart.SharedStringTable; // 使用物件來承接資料 var list = new List<Data>();
// 跳過欄位名稱的 row1 foreach (var row in sheetData.ChildElements.Select(x => x as Row).Skip(1)) { var data = new Data();
var path = @"D:\Import_WIP_Example.xlsx"; awaitusing FileStream fs = new(path, FileMode.Open); var xssWorkbook = new XSSFWorkbook(fs); var sheet = xssWorkbook.GetSheetAt(0); IRow headerRow = sheet.GetRow(0); int cellCount = headerRow.LastCellNum; // 使用物件來承接資料 var list = new List<Data>();
for (var i = (sheet.FirstRowNum + 2); i <= sheet.LastRowNum; i++) { var row = sheet.GetRow(i); if (row == null) continue; // 移除空白列 if (row.Cells.All(d => d.CellType == CellType.Blank)) continue;
var path = @"D:\Import_WIP_Example.xlsx"; ExcelPackage.LicenseContext = LicenseContext.Commercial; usingvar package = new ExcelPackage(new FileInfo(path));
var sheet = package.Workbook.Worksheets[0]; var startRowNumber = sheet.Dimension.Start.Row; var endRowNumber = sheet.Dimension.End.Row; var startColumn = sheet.Dimension.Start.Column; var endColumn = sheet.Dimension.End.Column;
var list = new List<Data>();
for (var currentRow = startRowNumber + 1; currentRow <= endRowNumber; currentRow++) { // 移除空白列 ExcelRange range = sheet.Cells[currentRow, startColumn, currentRow, endColumn]; if (range.All(c => !string.IsNullOrEmpty(c.Text)) == false) continue;