Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Read In Excel Column Names
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
Read In Excel Column Names
Miscellaneous
Thread ID:
01429660
Message ID:
01429660
Views:
90
I'm trying to load a data table with the names of the columns from an Excel file. I got this code from a Google search:
private static void GetExcelInfo()
{ 
    int i;
    DataTable dtTables;
    DataTable dtColumns;
    OleDbConnection myConn = new OleDbConnection();
    string ExcelFile = @"C:\Projects\Apex\Documents\Reports\MyFile.xls";
    string SheetName = "[Current MRP Action Messages$]";
    string XlsConn = @"provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ExcelFile + ";Extended Properties=\"Excel 8.0;HDR=NO;IMEX=1\"";

    myConn.ConnectionString = XlsConn;

    try
    {
        myConn.Open();
    }
    catch (Exception e)
    {
        throw e;
    }

    dtTables = myConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] {null, null, null, "TABLE"});

    dtColumns = myConn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] {null, null, SheetName, "TABLE"});

    myConn.Close();
}
The dtTables has all the sheet names in it, but the dtColumns is empty. Anyone know how to do this?
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Reply
Map
View

Click here to load this message in the networking platform