Solved

Line meaning

Posted on 2016-08-25
9
86 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
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 142

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 142

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 142

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 142

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

831 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