Password protected Excel

boss32178

New member
Joined
Apr 1, 2009
Messages
1
Ok, I have this Excel read this is working great my trouble is that my excel table is password protected. Can any one tell me what I need to do for this?
Thank you,

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace CK01
{
    class Program
    {
        static void Main(string[] args)
        {
            string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;"+
					"Data Source=C:\\CK01\\Book1.xls;"+
					"Extended Properties=" + (char)34 + "Excel 8.0;HDR=Yes;IMEX=1" + (char)34;


            //Create the connection

            System.Data.OleDb.OleDbConnection ExcelConnection =
            new System.Data.OleDb.OleDbConnection
                             (ConnectionString);

            //create a string for the query
            string ExcelQuery;

            //Sheet1 is the sheet name
            //create the query:
            //read column  header  from the Excel file
            ExcelQuery = "Select COST CTR,CUSTOMER NAME from [Sheet1$]"; // from Sheet1";

            //use "Select * ... " to select the entire sheet
            //create the command
            System.Data.OleDb.OleDbCommand ExcelCommand = new System.Data.OleDb.OleDbCommand(ExcelQuery, ExcelConnection);

            //Open the connection
            ExcelConnection.Open();

            //Create a reader
            System.Data.OleDb.OleDbDataReader ExcelReader;
            ExcelReader = ExcelCommand.ExecuteReader();

            //For each row after the first
            while (ExcelReader.Read())
            {
                Console.WriteLine((ExcelReader.GetValue(0)).ToString());
                Console.WriteLine(ExcelReader.GetValue(1).ToString());
            }
            ExcelConnection.Close();
        }
    }
}
 
Do you mean to say the excel file is password protected/ sheet is password protected, or the range is password protected. It is not clear to me :(

Thanks,
Vikas
 
Back
Top