Asp.net изображения gridview в excel
I want to export my gridview to excel using c# when i am exporting with Microsoft.office.intreop then in my image column System.Drawing.image is coming or when i have done with Response.Header then my images are coming but if image size is more than my image is coming out of row.
Что я уже пробовал:
<pre> protected void Unnamed_Click(object sender, EventArgs e) { System.Data.DataTable dts = new System.Data.DataTable(); dts.Columns.Add("UserId", typeof(Int32)); dts.Columns.Add("UserName", typeof(string)); dts.Columns.Add("Education", typeof(string)); dts.Columns.Add("Imagepath", typeof(Image)); // context.Response.BinaryWrite((Byte[])[ismg.]); dts.Rows.Add(1, "Suresh Dasari", "B.Tech", GetImageFromFile("~/images/EC.png")); dts.Rows.Add(2, "Suresh Dasarsi", "B.Tech", GetImageFromFile("~/images/EC.png")); Microsoft.Office.Interop.Excel._Application excel = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel._Workbook workbook = excel.Workbooks.Add(Type.Missing); Microsoft.Office.Interop.Excel._Worksheet worksheet = null; try { worksheet = workbook.ActiveSheet; worksheet.Name = "ExportedFromDatGrid"; int cellRowIndex = 1; int cellColumnIndex = 1; ////Loop through each row and read value from each column. for (int i = 0; i < dts.Rows.Count; i++) { for (int j = 0; j < dts.Columns.Count; j++) { //// Excel index starts from 1,1. As first Row would have the Column headers, adding a condition check. if (cellRowIndex == 1) { worksheet.Cells[cellRowIndex, cellColumnIndex] =dts.Columns[j].ColumnName; worksheet.Cells[cellRowIndex, cellColumnIndex].Font.FontStyle = FontStyle.Bold; } else { worksheet.Cells[cellRowIndex, cellColumnIndex] =dts.Rows[i][j].ToString(); } cellColumnIndex++; } cellColumnIndex = 1; cellRowIndex++; } worksheet.Columns.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft; worksheet.Columns.AutoFit(); ////Getting the location and file name of the excel to save from user. workbook.SaveAs("ss.xls", XlFileFormat.xlExcel12, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, false, XlSaveAsAccessMode.xlShared, XlSaveConflictResolution.xlLocalSessionChanges, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false); } catch (System.Exception ex) { // MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); } finally { excel.Quit(); workbook = null; excel = null; } } private static Image GetImageFromFile(string fileName) { string path = fileName; //check the existence of the file in disc if (File.Exists(path)) { Image image =new Image(); image.Url = path; return image; } else return null; }