Solved

Excel sort problem

Posted on 2011-03-08
2
1,067 Views
Last Modified: 2012-05-11
Hi, I have a excel sort problem with C#. Please look at my code.
xlRange.Sort((Excel.Range)xlWorkSheet1.Cells[1, 2], Excel.XlSortOrder.xlAscending,
            Type.Missing, Type.Missing, Excel.XlSortOrder.xlAscending,
            Type.Missing, Excel.XlSortOrder.xlAscending,
            Excel.XlYesNoGuess.xlNo, Type.Missing, Type.Missing,
            Excel.XlSortOrientation.xlSortRows,
            Excel.XlSortMethod.xlStroke,
            Excel.XlSortDataOption.xlSortNormal,
            Excel.XlSortDataOption.xlSortNormal,
            Excel.XlSortDataOption.xlSortNormal);

Open in new window

Here, three questions:
1) Cells[1, 2] means sort fron row 1, column 2?
2) What is the sort direction? I mean sort row or sort column?
3) I google search with msdn but not found the corresponding materials. Could you please give me a link?
Thanks.
0
Comment
Question by:zhshqzyc
2 Comments
 
LVL 6

Accepted Solution

by:
nandithaa earned 50 total points
ID: 35079815
Please refer following sites:
http://msdn.microsoft.com/en-us/library/wxks80sb%28v=vs.80%29.aspx
http://msdn.microsoft.com/en-us/library/wxks80sb.aspx


xlRange.Sort((Excel.Range)xlWorkSheet1.Columns[1, missing], Excel.XlSortOrder.xlAscending,
            Type.Missing, Type.Missing, Excel.XlSortOrder.xlAscending,
            Type.Missing, Excel.XlSortOrder.xlAscending,
            Excel.XlYesNoGuess.xlNo, Type.Missing, Type.Missing,
            Excel.XlSortOrientation.xlSortColumns,
            Excel.XlSortMethod.xlStroke,
            Excel.XlSortDataOption.xlSortNormal,
            Excel.XlSortDataOption.xlSortNormal,
            Excel.XlSortDataOption.xlSortNormal);

Open in new window


Hope this helps....
0
 

Author Comment

by:zhshqzyc
ID: 35083308
So if I want to sort row 1 but from the second cell to the end, I have to defind a range first.
 xlRange = xlWorkSheet1.get_Range("B1:" + GetExcelColumnName(nCols) + nRows.ToString(), Type.Missing);

Open in new window

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

777 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