locked
Read Image from excel file Issue RRS feed

  • Question

  • User-251267810 posted

    Hello every one.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;
          DataGrid1.DataBind();

        }

    ASPX Code
    ------------------------------------
    <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;

    connection.Open();
    dr = command.ExecuteReader(CommandBehavior.CloseConnection);

    DataTable excelData = new DataTable("ExcelData");
    excelData.Load(dr);

    dataGridView1.DataSource = excelData;


    Please help me if any body have solution for this issue

    Thanks,
    Sanjeev Sharma

    Thursday, November 18, 2010 9:25 AM

All replies