How do I iterate through rows in an excel table using epplus?

后端 未结 6 1233
暖寄归人
暖寄归人 2021-01-30 20:19

I am new to epplus, and i\'m trying to read some values from an excel table.

This is what I have so far:

var fileInfo = new FileInfo(filename);
using(var e         


        
6条回答
  •  南方客
    南方客 (楼主)
    2021-01-30 20:54

    While searching for help on the same problem, I stumbled across this link. It certainly worked for me! Definitely better than using Interop objects. :)

    I adapted it slightly though:

    var package = new ExcelPackage(new FileInfo("sample.xlsx"));
    
    ExcelWorksheet workSheet = package.Workbook.Worksheets[0];
    var start = workSheet.Dimension.Start;
    var end = workSheet.Dimension.End;
    for (int row = start.Row; row <= end.Row; row++)
    { // Row by row...
        for (int col = start.Column; col <= end.Column; col++)
        { // ... Cell by cell...
            object cellValue = workSheet.Cells[row, col].Text; // This got me the actual value I needed.
        }
    }
    

提交回复
热议问题