I use the following code to loop through the excel sheet using ExcelDataReader.
private void GetExcelSheetData(IExcelDataReader reader)
{
do
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
Debug.Log(reader.GetString(i));
}
Debug.Log(" row is over " + rowNumber);
}
} while (reader.NextResult());
}
This code works fine. However, I'm looking forward to dropping or skipping some rows as well as the columns. How do I manage to do so? I'm trying to read between row 3 to row 9 and column 4 to 15.
You can do it with if
statement, along with variables that point to current row and column:
private static void GetExcelSheetData(IExcelDataReader reader)
{
do
{
int rowNumber = 0;
while (reader.Read())
{
if (rowNumber >= 3 && rowNumber <= 9)
{
for (int i = 4; i <= 15; i++)
{
Debug.Log(reader.GetString(i));
}
Debug.Log(" row is over " + rowNumber);
}
rowNumber++;
}
}
while (reader.NextResult());
}
Is this what you need?