PC Review


Reply
Thread Tools Rate Thread

Cannot sort Tables in C#

 
 
=?Utf-8?B?QW5kcmV3IFdhbGFzemVr?=
Guest
Posts: n/a
 
      25th Oct 2006
I am having problems sorting Tables in Excel 2007 using C#. The below method
changes the cursor to ascending in the Table's header sort fields but fails
to sort the cells. Under debugger the SortField and Table ranges passed to
Excel look OK and Apply() executes without errors. Any help will be
appreciated.

Thanks,
Andrew

/// <summary>
/// Sort Table in ascending order by the specified keys
/// </summary>
/// <param name="inTable">input Table to sort</param>
/// <param name="inColumns">input key column names to use</param>
public static void SortTableByKeys(Excel.ListObject inTable, string[]
inColumns)
{
inTable.Sort.SortFields.Clear();
foreach (string column in inColumns)
{
inTable.Sort.SortFields.Add(inTable.ListColumns.get_Item(column).Range,
Excel.XlSortType.xlSortValues, Excel.XlSortOrder.xlAscending, Type.Missing,
Excel.XlSortDataOption.xlSortNormal);
}
inTable.Sort.SetRange(inTable.Range);
inTable.Sort.Orientation = Excel.XlSortOrientation.xlSortColumns;
inTable.Sort.MatchCase = false;
inTable.Sort.Header = Excel.XlYesNoGuess.xlYes;
inTable.Sort.SortMethod = Excel.XlSortMethod.xlPinYin;
inTable.Sort.Apply();
}

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort Tables JCO Microsoft Frontpage 2 1st Jun 2007 05:46 PM
Several Tables of Contents (sort of like sub tables?) in one docum =?Utf-8?B?bnljQ1RN?= Microsoft Word Document Management 6 31st Mar 2007 05:30 PM
sort tables =?Utf-8?B?S0pS?= Microsoft Excel Worksheet Functions 1 3rd Oct 2006 10:10 PM
cannot sort in tables? =?Utf-8?B?TmljayBC?= Microsoft Access 6 2nd Apr 2005 03:30 PM
Automatically Sort Tables =?Utf-8?B?dGFtYXRvNDM=?= Microsoft Excel Misc 2 22nd Mar 2005 07:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:09 AM.