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!