I have to ensure that each cell in an excel column contains values of the same data type.
In this sheet the first row contains the column header, therefore the data starts in row 2.
The First column should contain only integer values and the second column should contain strings. How to make sure that all values in the column have the same type or how to use tryparse in this validation?
This is the code which render the data in excel
for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
{
var P = new VPODSettlement();
P .POs = Convert.ToInt32(settlement.Cells[rowIterator,1].Value);
P .Am_title = settlement.Cells[rowIterator, 2].Value.toString();
Ps .Add(P);
}
.ToString
as you will loose the type. And you can use theworksheet.Cells
property which only contains cells that have actual content in the sheet. See if this helps: stackoverflow.com/questions/31537981/…. And this one: stackoverflow.com/questions/37495707/… – Ernie S