使用OpenXML在列中读取Excel表格数据

3
有没有一种使用OpenXML-SDK和C#按列而不是按行读取Excel表格的方法?
我已经尝试使用EPPlus包,但因为我的应用程序还使用了“.xslm”文件,而EPPlus不支持这些文件,所以我需要在OpenXML中找到一种读取列数据的解决方案。
如果有人有一个例子,那将会很有帮助。
谢谢 Sri
1个回答

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

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接