We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to loop through all rows present in Excel and add validation if there is error

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;

                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

I could not find your Excel template file, probably you forgot to attach it here. Please attach the template file and elaborate your requirements bit more by sharing expected output file.

I am not getting option to upload Excel file. It allows only images.
Can you please let me know how to share excel template?


Please zip your attachments/files and then attach the zipped archive.