Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using interop excel Library.
I am successful in creating excel so far but I want to embedd the object into excel cells which I am unable to do so.

using this code :

C#
foreach (DataRow r in dt.Rows)
            {
                iRow++;
                // add each row's cell data...


                iCol = 0;
                foreach (DataColumn c in dt.Columns)
                {
                    iCol++;
if (c.ColumnName == "Vendor Filename" && r[c.ColumnName] != null)
                    {
                        OLEObjects oleObjects = (Microsoft.Office.Interop.Excel.OLEObjects)


                        xlWorkSheet.OLEObjects(Type.Missing);

                        oleObjects.Add(
                            Type.Missing,   // ClassType
                           HttpContext.Current.Server.MapPath("~/Entitelement_Files/" +"xyz.jpg"),           // Filename
                            true,           // Link
                            false,          // DisplayAsIcon
                            Type.Missing,   // IconFileName
                            Type.Missing,   // IconIndex
                            Type.Missing,   // IconLabel
                            Type.Missing,   // Left
                            Type.Missing,   // Top
                            Type.Missing,   // Width
                            Type.Missing    // Height
                        );
                        objSheet = (_Worksheet)xlSheets.get_Item(1);
                        excel.Cells[iRow+1, iCol] = oleObjects;
                    

                    }
                    else
                    {

                        excel.Cells[iRow + 1, iCol] = r[c.ColumnName];
                    }
                }
            }


But this is not letting me achieve the task.
The pic is inserted randomly and moreover I am not sure what can be my object as it could a simple text file or a image or DB file or so on.

Kindly help.
Thanks
Posted

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