Read excel sheet data in columns using OpenXML

十年热恋 提交于 2019-12-10 21:57:40

问题


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


回答1:


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

}


来源:https://stackoverflow.com/questions/4715690/read-excel-sheet-data-in-columns-using-openxml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!