We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Column order problem with Cells.ImportDataTable method

Hi,

I am using the Cells.ImportDataTable method to load data from a datatable into a worksheet. I ordered the columns in the datatable in a specific way, but the Cells.ImportDataTable method is ignoring the column order and creating the columns n the worksheet alphabetically.

I would like to retain the column order of the datatable. Is there any setting to control this or is there anything else I can do? Is this an intended result on your (Aspose) part or maybe a bug?

Regards

Hi,

Well, I think you may specify your SQL query to fetch data accordingly.

E.g.., (I utilized Northwind data table Employees)

OleDbConnection con = new OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=d:\\test\\Northwind.mdb");
con.Open();

OleDbCommand cmd = new OleDbCommand("Select Title, EmployeeID, City from Employees",con);
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds,"Employees");

Workbook wb = new Workbook();
Worksheet sheet1 = wb.Worksheets[0];
Cells cells = sheet1.Cells;
//Import the datatable and it starts at A3 Cells
cells.ImportDataTable(ds.Tables["Employees"],true,2,0,false);
sheet1.AutoFitColumns();
wb.Save("d:\\test\\dtimports.xls");

Thank you.