0

I have (Kingsoft Spreadsheet) Excel workbook having 15 columns, in the 15th column there is picture saved in a cell. I am reading the excel file and creating a data table with respect to that. All things are working well except to store picture in data table. There can be number of rows each having different image in 15th column.

C# code:

public static DataTable GetDataTableFromExcel(string path, bool hasHeader)
{
    using (var pck = new OfficeOpenXml.ExcelPackage())
    {
        using (var stream = File.OpenRead(path))
        {
            pck.Load(stream);
        }
        var ws = pck.Workbook.Worksheets.First();    

        DataTable tbl = new DataTable();
        foreach (var firstRowCell in ws.Cells[1, 1, 1, ws.Dimension.End.Column])
        {
            tbl.Columns.Add(hasHeader ? firstRowCell.Text : string.Format("Column {0}", firstRowCell.Start.Column));
        }
        var startRow = hasHeader ? 2 : 1;

        for (int rowNum = startRow; rowNum <= ws.Dimension.End.Row; rowNum++)
        {
           // Inserting Data from Excel to Datatable.
            var wsRow = ws.Cells[rowNum, 1, rowNum, 15];
            DataRow row = tbl.Rows.Add();
            foreach (var cell in wsRow)
            {
                row[cell.Start.Column - 1] = cell.Text;
            }

        }
        return tbl;
    }
}

Note: I am using Kingsoft spreadsheets.

I am unable to find help to read image from a particular cell of excel.

Please help if anyone can.

Thanks in advance!

Ahmed Salah
  • 851
  • 2
  • 10
  • 29
  • already answerd in Stack Overflow! https://stackoverflow.com/questions/11993979/openxml-excel-extracting-cell-text-and-image-picture-data – Pradeep Kumar Feb 20 '18 at 08:42
  • @PradeepKumar I do think the ExcelPackage is a different library alltogether. – user6144226 Feb 20 '18 at 08:51
  • @PradeepKumar That solution is not working for me, I think that is because I am using OfficeOpenXml. I am unable to find Imagepart and Drawingpart in that package – Priyanka Bansal Feb 20 '18 at 09:00
  • It is, it's a free NuGet package called **EPPlus**. Kingsoft should provide documentation otherwise not sure if it's even possible. – Jeremy Thompson Feb 20 '18 at 09:02

1 Answers1

0

i think you are not imported namespaces

try importing following namespaces

using System.Drawing; using OfficeOpenXml.Drawing;