Force column order, Excel data table

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-06-10T20:14:44Z Indexed on 2010/06/10 20:22 UTC
Read the original article Hit count: 213

Filed under:
|

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;
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about excel