Sort Excel Column or ImportDataColumn that takes a DataView

Hi,

We have a datatable with all the available data, not sorted, not column ordered.
Column Ordering mean, if i have column1,column2,column3,column4 in datatable
I need to rearange the columns --> column4,column2,column1…

We need to bind this data to the Excel, After

1. Sorting the Data and

2. Re-Ordering the Columns.

3. Bind to Excel

My problem, here is,
1. If I create a DataView, I can sort the Data, but cannot
do the column ordering.

2. If I do ExcelCell.ImportDataColumn, which takes only a DataTable (which is not sorted !)

SO, If we have a overriding method ImportDataColumn which takes a DataView
that will solve our problem

OR If we can sort the Excel cell itself (using column name), after binding , will
also solve our Problem.

Pls. Help

Gopi

Hi Gopi,

Thanks for your suggestion. I will overload ImportDataColumn method to allow you import a column from a data view.

Thanks Laurence,

Sorry for misrepresenting Overload with (OverRide!) and Thanks for the Correction !

Do u know when this modification will be available ?

Gopi

It will be availabe at the start of next week.

Cool… That’s really fast ! and we really appreciate all you Guys hard work and quick response. Real good Customer Support.

Thanks,

Gopi

Hi Gopi,

Please download and try v3.4.1. This new method is supported now.

Works like a Charm ! Thanks you Guys. Wonderful Work.

Gopi

@vgopinath,
Aspose.Cells that replaced Aspose.Excel contains the function to import data columns. Earlier this function was available with the same name as ImportDataColumn however it was deprecated since version 18.12 and now is available as an overload function of ImportData. Refer to the following sample code that demonstrates this feature.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

// Create directory if it is not already present.
bool IsExists = System.IO.Directory.Exists(dataDir);
if (!IsExists)
    System.IO.Directory.CreateDirectory(dataDir);

// Instantiating a "Products" DataTable object
DataTable dataTable = new DataTable("Products");

// Adding columns to the DataTable object
dataTable.Columns.Add("Product ID", typeof(Int32));
dataTable.Columns.Add("Product Name", typeof(string));
dataTable.Columns.Add("Units In Stock", typeof(Int32));

// Creating an empty row in the DataTable object
DataRow dr = dataTable.NewRow();

// Adding data to the row
dr[0] = 1;
dr[1] = "Aniseed Syrup";
dr[2] = 15;

// Adding filled row to the DataTable object
dataTable.Rows.Add(dr);

// Creating another empty row in the DataTable object
dr = dataTable.NewRow();

// Adding data to the row
dr[0] = 2;
dr[1] = "Boston Crab Meat";
dr[2] = 123;

// Adding filled row to the DataTable object
dataTable.Rows.Add(dr);

// Instantiate a new Workbook
Workbook book = new Workbook();

Worksheet sheet = book.Worksheets[0];

// Create import options
ImportTableOptions importOptions = new ImportTableOptions();
importOptions.IsFieldNameShown = true;
importOptions.IsHtmlString = true;

// Importing the values of 2nd column of the data table
sheet.Cells.ImportData(dataTable, 1, 1, importOptions);

// Save workbook
book.Save(dataDir + "DataImport.out.xls");

For more information about importing data into Excel, refer to the following article:
Importing from data column

Here is the free trial version available that can be used to test the new product features:
Aspose.Cells for .NET (Latest Version)

Here is a ready-to-run solution that can be used to test the product features with minimal effort.