Solved

Line meaning

Posted on 2016-08-25
9
89 Views
Last Modified: 2016-08-26
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

0
Comment
Question by:HuaMinChen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 500 total points
ID: 41771242
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 41771279
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41771294
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:HuaMinChen
ID: 41771302
To the original line, why does it need to check both Min and Max in there?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41771337
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 41771352
Is such line only destined to check for non-merged cell? How to detect that relevant cell is a merged cell?
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 41771372
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 41771376
Thanks a lot Hengel. Where is the documentation located at?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41771406
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

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question