结合使用LINQ和Open XML(Excel) [英] Using LINQ with Open XML (Excel)

查看:81
本文介绍了结合使用LINQ和Open XML(Excel)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Excel工作表,并且正在使用 Open XML SDK 2.0 处理它.场景是,在我的Excel工作表中有一列包含日期.我需要从该列中获取最大和最小日期.

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.

但是由于最优,我想使用 LINQ 来获取最小和最大日期.

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?

推荐答案

感谢所有人

我曾经这样使用

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];

这篇关于结合使用LINQ和Open XML(Excel)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆