How to validate person ages in existing XLS spreadsheet document and mark persons with non-teenager age with red color

This source code sample demonstrates how to use Bytescout Spreadsheet SDK to open existing Excel (XLS) document and check the column with person ages: check if age is accepted (age should be teenager age from 10 to 19) and if age is not a teeneger age (less than 10 or greater than 19) so this person should be marked in the spreadsheet with red color

Download example source code: bytescoutxls_validate_if_cell_value_in_range.zip (8 KB)

Output spreadsheet (XLS) where persons with non-teenager age are marked with red color:

document with persons name and age: persons with non-teenager age are marked with red color

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using Bytescout.Spreadsheet;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
// Create new Spreadsheet
Spreadsheet document = new Spreadsheet(“Data.xls”);

// Get worksheet by name
Worksheet worksheet = document.Workbook.Worksheets.ByName(“Sample”);

// Minimum age
int RangeMin = 10;
// Maximum age
int RangeMax = 19;

// Spellcheck words
for (int i = 1; i < 8; i++)
{
// Set current cell
Cell currentCell = worksheet.Cell(i, 1);

// Check current cell
if (System.Convert.ToInt32(currentCell.Value) < RangeMin || System.Convert.ToInt32(currentCell.Value) > RangeMax)
{
// Set fill pattern
currentCell.FillPattern = Bytescout Spreadsheet.Constants.PatternStyle.Solid;

// Markup wrong cell by red color
currentCell.FillPatternForeColor = System.Drawing.Color.Red;
}
}

// Save document
document.SaveAs(“CheckedData.xls”);

// Close document
document.Close();

// open generated XLS document in default program
Process.Start(“CheckedData.xls”);
}
}
}

Download example source code: bytescoutxls_validate_if_cell_value_in_range.zip (8 KB)