问题描述
我有一个 Excel 表格,我正在使用 Open XML SDK 2.0 处理它.情况是,我的 excel 表中有一个包含日期的列.我需要从该列中获取最大和最小日期.
我可以通过循环并到达该单元格,进行比较并找到所需的答案来做到这一点.
但由于优化,我想通过使用 LINQ 来获取最小和最大日期.
有可能吗?如果是,那么如何?
推荐答案
谢谢大家
我是这样用的
IEnumerable<Cell> cells = workSheetPart.Worksheet.Descendants<Cell>().Where(c => string.Compare(GetColumnName(c.CellReference.Value), strIndex, false) == 0).OrderBy(c => c.CellValue.Text);
像这样获取最小值和最大值
int cellCount = cells.Count(); Cell MaxCell = cells.ToArray()[0]; Cell MinCell = cells.ToArray()[cellCount - 1];
问题描述
I have an excel sheet and I am processing it by using Open XML SDK 2.0. The scenario is, There is a column which contains date in my excel sheet. I need to get the maximum and minimum date from that column.
I can do this by looping and reaching to that cell, doing comparisons and finding desired answer.
But due to optimality I want to do this by using LINQ to get Minimum and maximum dates.
Is it possible to do so? If yes, then how?
推荐答案
Thanks to all
I have used like this
IEnumerable<Cell> cells = workSheetPart.Worksheet.Descendants<Cell>().Where(c => string.Compare(GetColumnName(c.CellReference.Value), strIndex, false) == 0).OrderBy(c => c.CellValue.Text);
And getting min and max values like this
int cellCount = cells.Count(); Cell MaxCell = cells.ToArray()[0]; Cell MinCell = cells.ToArray()[cellCount - 1];
相关问答
相关标签/搜索