我想将gridview导出到excel文件,但问题是我在gridview中存储了存储在数据库表中的图像..我存储整个图像的方式不是图像的路径,我想导出图像还有代码 但是当我运行它时它给出例外..请帮助.. 谢谢
saveFileDialog1.Filter = "Excel (*.xls)|*.xls";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if (!saveFileDialog1.FileName.Equals(String.Empty))
{
FileInfo f = new FileInfo(saveFileDialog1.FileName);
if (f.Extension.Equals(".xls"))
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
int i = 0;
int j = 0;
for (int h = 1; h < grid.Columns.Count + 1; h++)
{
xlWorkSheet.Cells[1, h] = grid.Columns[h - 1].HeaderText;
}
for (i = 0; i <= grid.RowCount - 1; i++)
{
for (j = 0; j <= grid.ColumnCount - 1; j++)
{
DataGridViewCell cell = grid[j, i];
xlWorkSheet.Cells.Borders.LineStyle = Excel.XlLineStyle.xlContinuous;
xlWorkSheet.Columns.AutoFit();
xlWorkSheet.Cells[i + 2, j + 1] = cell.FormatedValue;
}
}
xlWorkBook.SaveAs(saveFileDialog1.FileName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkSheet);
releaseObject(xlWorkBook);
releaseObject(xlApp);
MessageBox.Show("Excel file created , you can find the file " + saveFileDialog1.FileName);
}
else
{
MessageBox.Show("Invalid file type");
}
}
else
{
MessageBox.Show("You did pick a location " +
"to save file to");
}
}
这是excel表的图片,但在图片栏中图片没有显示,但文字“System.drawing.bitmap”