Line meaning

Hi,
What is the meaning of this?
IEnumerable<DocumentFormat.OpenXml.Spreadsheet.Column> ic = cs.Elements<DocumentFormat.OpenXml.Spreadsheet.Column>().Where(r => r.Min == columnIndex).Where(r => r.Max == columnIndex);

Open in new window

LVL 11
HuaMin ChenSystem AnalystAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
Please refer to the documentation, which is really complete on that topic:
DocumentFormat.OpenXml.Spreadsheet.Column

it's not "merged column", in this regards, but a column "info" that only applies to that requested column, ignoring hence any other "info" that would apply to more columns, even if the requested column would be included.

if you wanted to return "all" the colum "info" object that cover the requested column:

.Where(r => r.Min <= columnIndex)
.Where(r => r.Max >= columnIndex);
0
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
This is the variable, of the given type, that is getting assigned to the result of the LINQ expression that follows. the reason of the IEnumerable is because of the LINQ returns a collection, with eventually only 1 (or 0 items) in it
IEnumerable<DocumentFormat.OpenXml.Spreadsheet.Column> ic =

this is the collection from where the LINQ will "filter" from ...
cs.Elements<DocumentFormat.OpenXml.Spreadsheet.Column>()

... applying the 2 conditions, saying the processed item (from the above collection) is named r, and making a test on r.<someproperty> == <somevariable>
.Where(r => r.Min == columnIndex)
.Where(r => r.Max == columnIndex);
if the condition on "r" is fulfilled, the object will be returned into the result collection
0
 
HuaMin ChenSystem AnalystAuthor Commented:
Many thanks Hengel.
Is it returning one array per relevant spreadsheet columns, by such line?

What is the purpose to 'care' about only 'First()' below?
                                                    IEnumerable<DocumentFormat.OpenXml.Spreadsheet.Column> ic = cs.Elements<DocumentFormat.OpenXml.Spreadsheet.Column>().Where(r => r.Min == columnIndex).Where(r => r.Max == columnIndex);
                                                    if (ic.Count() > 0)
                                                    {
                                                        DocumentFormat.OpenXml.Spreadsheet.Column c = ic.First();
                                                        double cc = c.Width;
                                                        sw.WriteLine("Cell width: {0}", cc.ToString());
                                                    }

Open in new window

0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
First() returns what the name is suggesting: the first (and eventually the only) item from the collection.
this avoids to "loop" on the collection.
0
 
HuaMin ChenSystem AnalystAuthor Commented:
To the original line, why does it need to check both Min and Max in there?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I don't know. that is the application logic presumably
it surely tries to consider only cells that are not merged, and at exaclty that position
0
 
HuaMin ChenSystem AnalystAuthor Commented:
Is such line only destined to check for non-merged cell? How to detect that relevant cell is a merged cell?
0
 
HuaMin ChenSystem AnalystAuthor Commented:
Thanks a lot Hengel. Where is the documentation located at?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
sorry, I had not pasted the URL above:
https://msdn.microsoft.com/en-us/library/documentformat.openxml.spreadsheet.column(v=office.14).aspx

you can find such information really quickly, using google, you search this:
DocumentFormat.OpenXml.Spreadsheet.Column site:microsoft.com
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.