Home » excel » c# – Read excel sheet data in columns using OpenXML

c# – Read excel sheet data in columns using OpenXML

Posted by: admin April 23, 2020 Leave a comment

Questions:

Is there a way to read the excel sheet column wise rather than in rows using OpenXML-SDK & C#.

I have already tried using EPPlus package, but faced some problems because my application also uses “.xslm” files which are not supported by EPPlus. So, I need a solution in OpenXML for reading data in columns.

If anyone has a example, that will help.

Thanks
Sri

How to&Answers:
    WorksheetPart worksheetPart = (WorksheetPart)document.WorkbookPart.GetPartById(sheets.First().Id);


// Get the cells in the specified column and order them by row.
IEnumerable<Cell> cells = worksheetPart.Worksheet.Descendants<Cell()
.Where(c => string.Compare(GetColumnName(c.CellReference.Value),
columnName, true) == 0).OrderBy(r => GetRowIndex(r.CellReference));

foreach (var cell in cells)
{

}