I need to sort across multiple columns in Excel using C#. I am using Microsoft.Office.Interop.Excel for doing this. But the Range.Sort allows me to sort across only three columns. I want to sort across more than three columns? Is there a way that I can use the Excel.Range.Sort method to sort across more than three columns?
相关问题
- Excel sunburst chart: Some labels missing
- Error handling only works once
- How do I create a multidimensional array of object
- Excel formula in VBA code
- Excel VBA run time error 450 from referencing a ra
相关文章
- Get column data by Column name and sheet name
- programmatically excel cells to be auto fit width
- Unregister a XLL in Excel (VBA)
- How to prevent excel from truncating numbers in a
- How to print a docx to a specific printer using Mi
- numeric up down control in vba
- Declare a Range relative to the Active Cell with V
- What's the easiest way to create an Excel tabl
Before Excel 2007 you were limited to 3 sort keys -
Range.Sort
won't let you use more. If that's your target version then you'll need to get creative: a couple of possible ideas being to pull the data into your C# code and sort it there, or build an extra worksheet column containing the concatenated keys, then applySort
as normal.If you're using Excel 2007 or later exclusively, then there's a much more flexible sorting capability available:
Worksheet.Sort
. I built a 30x10 table of random numbers inA1:J30
and recorded a macro that sorted on the first five columns. This is what I got (after cleaning and de-duplicating the code somewhat):That should be fairly easy to apply to your C# code...