Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get/read picture from Excel file (xlsx) using EPPlus

Tags:

c#

epplus

Let's assume I have a worksheet named sheet1 which contain a picture named pic_001 How can I get this picture as System.Drawing.Image object.

like image 616
IdontCareAboutReputationPoints Avatar asked Jan 07 '23 07:01

IdontCareAboutReputationPoints


2 Answers

OK I found out how to:

public static Image GetImage(string sheetname, ExcelPackage excelFile)
    {
      var sheet = excelFile.Workbook.Worksheets[sheetname];
      var pic = sheet.Drawings["pic_001"] as ExcelPicture;
      return pic.Image;
    }
like image 118
IdontCareAboutReputationPoints Avatar answered Jan 08 '23 20:01

IdontCareAboutReputationPoints


all xlsx files are really zip files. you can copy/rename the .xlsx extension to .zip and navigate the folder hierarchy yourself. navigate to xl/media to see your images. there are certainly more efficient ways of doing this, but this is a quick and dirty solution that will get the job done.

like image 34
Maxwell Corbin Avatar answered Jan 08 '23 22:01

Maxwell Corbin