Solved

Line meaning

Posted on 2016-08-25
9
75 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
  • 5
  • 4
9 Comments
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
Comment Utility
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 142

Expert Comment

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

Author Comment

by:HuaMinChen
Comment Utility
To the original line, why does it need to check both Min and Max in there?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Comment Utility
Is such line only destined to check for non-merged cell? How to detect that relevant cell is a merged cell?
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
Comment Utility
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
Comment Utility
Thanks a lot Hengel. Where is the documentation located at?
0
 
LVL 142

Expert Comment

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

744 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now