Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I work in windows form application c# vs 2015
I can insert data in excel but image cannot insert
when insert another data i using
System.Data.OleDb.OleDbCommand excelCommand = new System.Data.OleDb.OleDbCommand("INSERT INTO [AllPrinting$](UserID,UserName,Country,Member) VALUES (?,?,?,?)", excelConnection);

and i can insert but image cannot insert
how to insert image in excel sheet ?
my insert i need is
"INSERT INTO [AllPrinting$](UserID,UserName,Country,Member,Imag) VALUES (?,?,?,?,?)"

so that how to insert image on excel based on ID OR No
I Search more on internet but not got any thing ?

What I have tried:

How to insert image in excel 2007 ?
Posted
Updated 7-Mar-17 2:34am
v2

1 solution

I'm sorry, but this is not possible using OLEDB.

OLEDB is a database interface and supports only cell based import/export for Excel. But images are not stored within cells with Excel. They are separate objects just shown above cells.

[EDIT]
If you need to export images you have to choose a method that supports it.

Excel Automation / Microsoft Office Interop (requires installed Excel)
How to automate Microsoft Excel from Microsoft Visual C#.NET[^]

For the new (Office 2007 XLSX) file formats you can use the Open XML SDK:
Welcome to the Open XML SDK 2.5 for Office[^]
Read and write Open XML files (MS Office 2007)[^]

There are also third party libraries (free and commercial). From my point of view these should be only used for the old XLS file format and when using automation is not possible (Excel not installed on all clients).

Just query a search engine with the above keywords (e.g. "c# excel export <method>"; optional also with "image") to get more information.
[/EDIT]
 
Share this answer
 
v2
Comments
ahmed_sa 7-Mar-17 8:40am    
so that what i do to solve my problem
i can accept any solution
Jochen Arndt 7-Mar-17 8:54am    
I have updated my solution.
ahmed_sa 7-Mar-17 8:44am    
can you give me any trick to solve proble
actually i need to add image in excel to show on report rdlc
can you tell me what i do to solve that problem
ahmed_sa 7-Mar-17 9:01am    
thank you for reply
this is add image to excel but not insert as field with id and name and country
Jochen Arndt 7-Mar-17 9:06am    
"OLEDB is a database interface and supports only cell based import/export for Excel".

That means:
It can't add any other data to Excel files besides cell content.

You need an Excel export method that can export images (and can probably position them on the sheet).

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