Read Image From Excel File

Nov 18, 2010 at 12:07 PM


I’m trying to read images from an excel sheet, but i didn't find any API in codeplex, So please any body know this olution in codeplex. please give the reply

Because I’m trying to read images from an excel file using OleDbDataReader. My excel file has 6 columns of data, the first 5 are all text but the last is image. While I’m reading the record, It’s doing fine on the first 5 columns but return me with a “blank” for the sixth column.

Here is my demonistration code:

  protected void btnImportExcelFile_Click(object sender, EventArgs e)

      string strConn;
      strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
      "Data Source=C:\\exceltest.xls;" +
      "Extended Properties=Excel 8.0;";
      OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM Sheet1$]", strConn);

      DataSet myDataSet = new DataSet();
      myCommand.Fill(myDataSet, "Sheet1");
      DataGrid1.DataSource = myDataSet.Tables["Sheet1"].DefaultView;


<asp:Button ID="btnImportExcelFile" runat="server" OnClick="btnImportExcelFile_Click"
Text="Import Excel File" /></div><br />
<asp:DataGrid id=DataGrid1 runat="server"/>

 //DataReader approach also not working

OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;Data Source=C:\Temp\Test1.xls;Extended Properties=Excel 8.0");
OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", connection);
OleDbDataReader dr;

dr = command.ExecuteReader(CommandBehavior.CloseConnection);

DataTable excelData = new DataTable("ExcelData");

dataGridView1.DataSource = excelData;

Thanks & Reagards,

Sanjeev Sharma