gembox-spreadsheet

Is there a way to import an image from excel to a PictureBox?


I am writing an application that works with Excel files. So far I have been using Gembox spreadsheet to work with excel files. However, I discovered using Gembox spreadsheet I can save pics to excel files, but not retrieve them. Anyone can recommend how to retrieve a pic from excel file? Thank you


Solution

  • Here is how you can retrieve an image from an Excel file with GemBox.Spreadsheet:

    ExcelFile workbook = ExcelFile.Load("Sample.xlsx");
    ExcelWorksheet worksheet = workbook.Worksheets.ActiveWorksheet;
    
    // Select Picture element.
    ExcelPicture picture = worksheet.Pictures[0];
    
    // Import to PictureBox control.
    this.pictureBox1.Image = Image.FromStream(picture.PictureStream);
    
    // Or write to file.
    File.WriteAllBytes("Sample.png", picture.PictureStream.ToArray());