Force column order, Excel data table
- by Chris
I have a Excel Workbook that I use as a report template. I change the datasource on each pivot and datatable in a C# app. When I change the datatable datasource it tweeks the columns. Is there a way to force the column order?
private void RefreshRawData(string dataSource, string connection)
{
xl._Worksheet ws = (xl._Worksheet)xlTemplate.Worksheets["Raw Data"];
xl.ListObject table = ws.ListObjects["Table_ExternalData_1"];
xl.QueryTable qt = table.QueryTable;
qt.CommandText = dataSource;
qt.Connection = GetExcelConnectionString((string)qt.Connection);
qt.BackgroundQuery = false;
qt.Refresh(m);
Marshal.ReleaseComObject(ws);
Marshal.ReleaseComObject(table);
Marshal.ReleaseComObject(qt);
ws = null;
table = null;
qt = null;
}