Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Line meaning

Posted on 2016-08-25
9
Medium Priority
?
130 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 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 2000 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 11

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
Technology Partners: 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 11

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 11

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 2000 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 11

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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

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.
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

916 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