how to read image in datagridview from excel sheet
i am having a excel sheet containing student details with photos...i want to read all the details along with photo in datagridview...i am not able to read image..
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kyle StoryPosted Nov 26, 2014, 3:55 AM
ExcelFile ef = ExcelFile.Load(openFileDialog.FileName);
// From ExcelFile to DataGridView.
DataGridViewConverter.ExportToDataGridView(ef.Worksheets.ActiveWorksheet, this.dataGridView1, new ExportToDataGridViewOptions() { ColumnHeaders = true });
ExcelFile ef = new ExcelFile();
ExcelWorksheet ws = ef.Worksheets.Add("DataGridView Sheet");
// From DataGridView to ExcelFile.
DataGridViewConverter.ImportFromDataGridView(ws, this.dataGridView1, new ImportFromDataGridViewOptions() { ColumnHeaders = true });
ef.Save(saveFileDialog.FileName);
The code uses this Excel component for .NET framework. Now regarding your second task, I'm not sure what you need. As you mentioned you have student photos in an excel sheet and with the above code you will get those photos in DataGridView cells.
Again I'm not sure but I presume you want to change these photos, then you can just change them when user clicks on them, like this:
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
var cell = ((DataGridView)sender).Rows[e.RowIndex].Cells[e.ColumnIndex];
if (cell.FormattedValueType == typeof(Image))
cell.Value = Image.FromFile(@"C:\New Photo.png");
}
Munesh SharmaPosted Oct 7, 2014, 3:12 AM
Shradha KalePosted Oct 7, 2014, 12:34 AM
(winform) GridView cells display system. Drawing. Bitmap don't display picture
Shradha KalePosted Oct 6, 2014, 11:25 PM
Sagar PardeshiPosted Oct 6, 2014, 8:24 AM
http://www.codeproject.com/Articles/28269/Exporting-a-DataGridView-to-an-Excel-PDF-image-fil