Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read excel sheet data in columns using OpenXML

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

like image 221
Srikanth K Avatar asked Jul 14 '26 14:07

Srikanth K


1 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)
{

}
like image 115
Dean Kuga Avatar answered Jul 17 '26 18:07

Dean Kuga