I was earlier successful at converting Excel to datatable, but now, I have weirdly formatted table, following picture will show excel table, and table that I want to achieve.
var workbook = Workbook.Load("file.xls");
var worksheet = workbook.Worksheets[0];
var cells = worksheet.Cells;
var dataTable = new DataTable("datatable");
for (int colIndex = cells.FirstColIndex; colIndex <= cells.LastColIndex; colIndex++)
{
dataTable.Columns.Add(cells[0, colIndex].StringValue);
}
for (int rowIndex = cells.FirstRowIndex; rowIndex <= cells.LastRowIndex; rowIndex++)
{
var values = new List<string>();
foreach(var cell in cells.GetRow(rowIndex))
{
values.Add(cell.Value.StringValue);
}
dataTable.LoadDataRow(values.ToArray(), true);
}
This is the code. When I use this with mentioned .xls I'm getting "price: row shifted left. Example: https://i.stack.imgur.com/2jZQY.png So, any help about how to solve this is more than welcome. Thanks.