Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Reading Excel Files with OLEDB

RSS
Modified on Tue, Mar 08, 2011, 5:25 PM by Administrator Categorized as Microsoft Office, ·Net Framework
{copytext|code}
static void LoadExcelFile(string file, string sheet)
{
    // Use this connection string template for older (pre-2007) version of Excel
    //string s = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file 
    //    + ";Extended Properties=Excel 8.0";

    // Use this connection string template for Excel 2007
    string s = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + file 
        + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\";";

    OleDbConnection conn = new OleDbConnection(s);
    OleDbDataAdapter da = new OleDbDataAdapter("select * from [" + sheet + "$]", conn);
    DataTable dt = new DataTable();
    da.Fill(dt);
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.