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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sagar PardeshiRank #103 · 20.8K reputationPosted Oct 6, 2014, 4:24 AM EDT
http://www.codeproject.com/Articles/28269/Exporting-a-DataGridView-to-an-Excel-PDF-image-fil
Shradha Kale46 reputationPosted Oct 6, 2014, 7:25 PM EDT
Shradha Kale46 reputationPosted Oct 6, 2014, 8:34 PM EDT
(winform) GridView cells display system. Drawing. Bitmap don't display picture
Munesh SharmaRank #174 · 13.9K reputationPosted Oct 6, 2014, 11:12 PM EDT
Kyle Story24 reputationPosted Nov 25, 2014, 10:55 PM EST
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");
}