Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi All
I am importing data from an excel file to sql table. It is working fine, but problem is that my excelsheet contains images. Now i have to store the images in Upload folder in my project and path in table.
I am using below code to get datatable from excel file
public DataTable readdata(String sheetname, String filename)
        {
            OleDbConnection MyConnection = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source='" + filename + "'; Extended Properties=Excel 8.0;");
            OleDbDataAdapter MyCommand = new OleDbDataAdapter("select * from [" + sheetname + "]", MyConnection);
            DataTable dt = new DataTable();
            MyCommand.Fill(dt);
            MyConnection.Close();
            MyConnection.Dispose();
            return dt;
        }


But it is showing the image column blank.

Can anyone please suggest me how to get image from excel file.

Thanks in advance
Posted
Comments
Herman<T>.Instance 13-Mar-12 7:30am    
have you tried only to select the imagefield like cast(imagefield as image) ?
Sharma Richa 13-Mar-12 7:36am    
i tried to use cast(picture as image) but it is giving error:
IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
shreekar 13-Mar-12 10:29am    
Try displaying the fields collection of the created datatable. This is to ensure you actually get the image column in the datatable and that it contains something.
If there is no value in the Image column, look at how that image column is formatted in the source Excel sheet. Try some simple VBA inside the Excel to read the data and see where that takes you.

1 solution

Excel does not allow you to insert a picture into a cell.
Pictures are inserted into the worksheet and will always float.
One of the properties of a picture can be set to "move and size with cells" but that only moves or stretches the picture when the underlying rows and columns are inserted, deleted or sized. It does not confine a picture to a cell.

And since they're not part of a cell you can't export them to a table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900