Home > Articles > .Net Framework Articles > Sorting in Excel Spreadsheet from Windows Form

Sorting in Excel Spreadsheet from Windows Form

by kumbhani bhavesh   on Sep 21, 2016   Category: .Net Framework  | Level: Advance  |  Views: 884    |  Points: 100   
Like this article? Bookmark and Share:
In this article you will see how to sort Excel data and save them in your working location with the help of spire.xls from spire.

Introduction

In this article you will see how to sort Excel data and save them in your working location with the help of spire.xls from spire.

Sorting data is an integral part of data analysis. You might want to arrange a list of names in alphabetical order, compile a list of product inventory levels from highest to lowest. Sorting data helps you quickly visualize and understand your data better, organize and find the data that you want, and ultimately make more effective decisions.

Sort criteria for an Excel table are saved with the workbook so that you can reapply the sort to that table each time that you open the workbook, but sort criteria are not saved for a range of cells. If you want to save sort criteria so that you can periodically reapply a sort when you open a workbook, it's a good idea to use a table. This is especially important for multicolumn sorts or for sorts that take a long time to create.

This article will present how we can integrate Excel spreadsheet in a Windows Form Application as well as implement many more feathers (like MS Excel) using http://viewerexcel.codeplex.com/ 

Sort text

  1. Select a column of alphanumeric data in a range of cells, or make sure that the active cell is in a table column containing alphanumeric data.
  2.  On the Data tab, in the Sort & Filter group, do one of the following:

a.     To sort in ascending alphanumeric order, click (Sort A to Z).

b.     To sort in descending alphanumeric order, click (Sort Z to A).

 Below is the screenshot of the spreadsheet program created with this control.

Follow some step for inserting lib file in your coding

1)   Right Click References In your visual studio Program and Select add References


2)One pop-up will open, select Browse tab at left side and  Click 'Browse...' button


3) Choose 'Spire.Spreadsheet.dll' in open file dialog and click on add button


4) Click 'OK', then the controls including 'Spreadsheet' and 'Formula Box' will be successfully added to Toolbox

 

Press Ctrl+Z until you've fixed your mistake.Or press Alt+Backspace to do the same thing.If you prefer your mouse, click Undo on the Quick Access Toolbar.

Use it after including Spire.Xls; lib file at the header of your coding

Below image are see you output of my action for sorting data 

Hear, are the full coding and image of output

For a-z sorting data



Spire.Spreadsheet.Forms.CellRangeInfo cri = spreadsheet1.ActiveWorksheet.GetSelectedRange();          

Spire.Spreadsheet.Forms.CellRangeInfo cri = spreadsheet1.ActiveWorksheet.GetSelectedRange();

if(cri == null)

return;

int columnCount = cri.Right - cri.Left;

if(columnCount > 0)

{

 spreadsheet1.ActiveWorksheet.SortColumns(cri.Left, columnCount + 1,

Spire.Spreadsheet.Forms.SortOrder.Ascending, false);

    }

 else

{

 spreadsheet1.ActiveWorksheet.SortColumn(cri.Left,

Spire.Spreadsheet.Forms.SortOrder.Ascending, false);

  }

spreadsheet1.Refresh();


For z-a soring data


Spire.Spreadsheet.Forms.CellRangeInfo cri =

spreadsheet1.ActiveWorksheet.GetSelectedRange();

if(cri == null)

return;

 int columnCount = cri.Right - cri.Left;

if(columnCount > 0)

{

   spreadsheet1.ActiveWorksheet.SortColumns(cri.Left, columnCount + 1,

Spire.Spreadsheet.Forms.SortOrder.Descending, false);

}

else

{

spreadsheet1.ActiveWorksheet.SortColumn(cri.Left,

Spire.Spreadsheet.Forms.SortOrder.Descending, false);

}

spreadsheet1.Refresh();




Like this article? Bookmark and Share:

Most viewed Articles

User Comments


No response found, be the first to review this article.

Submit feedback about this article

Please sign in to post feedback

Latest Posts