Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Read In Excel Column Names
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Read In Excel Column Names
Divers
Thread ID:
01429660
Message ID:
01429660
Vues:
91
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
Répondre
Fil
Voir

Click here to load this message in the networking platform