Hi team,
I am trying to read uploaded Excel file. In this I want to read all uploaded data.
1.Validate Column Headers
2.Validate Rows
I am unable to do 2nd part i.e not getting exact cell indexes.
Workbook workbook = new Workbook(fileName);
Worksheet sheet = workbook.Worksheets[0];
Cells cells = sheet.Cells;
int maxrow = endCell.Row;
var maxrow1 = cells.EndCellInRow(0);
Dictionary<int, string> allErrors = ValidateRow(sheet);
public Dictionary<int, string> ValidateRow(Worksheet worksheet)
{
Dictionary<int, string> rowErrors = new Dictionary<int, string>();
for (int row = 0; row <= worksheet.Cells.MaxDataRow; row++)
{
for (int col = 0; col <= worksheet.Cells.MaxDataColumn; col++)
{
var cellVal = worksheet.Cells[row, col].StringValue;
Console.WriteLine(cellVal);
if (cellVal.Equals(""))
{
rowErrors.Add(row, "Please enter value Mandatory field");
//I am getting error here
}
}
}
return rowErrors;
}
Please let me know what would be best way to solve this