c# - Writing Image on a Cell of an excel in interop? -
i doing export excel .but have export images in excel cell.
public void generateandsaveexcel(dataset ds) { try { bool excelcreated = createexcelapplication(); bool workbookcreated = createworkbook(); if (excelcreated && workbookcreated) { bool worksheetadded = addworksheet(); if (worksheetadded) { createheader(ds.tables[0].columns); addrows(ds.tables[0].rows, ds.tables[0].columns); save(@"c:\worksheet1.xlsx"); } } else { } } catch (system.unauthorizedaccessexception) { } catch (system.runtime.interopservices.comexception) { } catch (system.io.ioexception) { } { excelapp.quit(); workbook = null; worksheet = null; dispose(); } }
here have columns id,name,sereenshot1,sereenshot2. sereenshot1,sereenshot2 image byte array.
i doing calculation in addrows method
public void addrows(datarowcollection datarows, datacolumncollection colmap) { microsoft.office.interop.excel.worksheet worksheet = worksheets.first(); string startindex = "b1"; microsoft.office.interop.excel.range range = worksheet.get_range(startindex, missing.value); int rowindex = 2; foreach (var row in datarows) { int colindex = 1; foreach (datacolumn column in colmap) { range = (microsoft.office.interop.excel.range)worksheet.cells[rowindex, colindex++]; object value = ((system.data.datarow)(row)).itemarray[column.ordinal]; if (column.columnname != "screenshot1" && column.columnname != "screenshot2") { range.set_value(microsoft.office.interop.excel.xlrangevaluedatatype.xlrangevaluedefault, value); } if (column.columnname == "screenshot1" && !string.isnullorempty(value.tostring())) { string path = configurationsettings.appsettings["imagepathpath"] + @"\img" + ((system.data.datarow)(row)).itemarray[0].tostring() + "srn1" + ".jpg"; worksheet.shapes.addpicture(path, microsoft.office.core.msotristate.msofalse, microsoft.office.core.msotristate.msoctrue, 10, 10, 200, 200); } if (column.columnname == "screenshot2" && !string.isnullorempty(value.tostring())) { string path = configurationsettings.appsettings["imagepathpath"] + @"\img" + ((system.data.datarow)(row)).itemarray[0].tostring() + "srn1" + ".jpg"; worksheet.shapes.addpicture(path, microsoft.office.core.msotristate.msofalse, microsoft.office.core.msotristate.msoctrue, 10, 10, 100, 100); } } rowindex++; } }
here working fine images coming ...but how determine position cell of image.
now images coming not in cell,,please help.here have use interop only.i want fit image in cell
Comments
Post a Comment