ByteScout Spreadsheet SDK - C# - Validate Cells with Dates - ByteScout

ByteScout Spreadsheet SDK – C# – Validate Cells with Dates

  • Home
  • /
  • Articles
  • /
  • ByteScout Spreadsheet SDK – C# – Validate Cells with Dates

validate cells with dates in C# with ByteScout Spreadsheet SDK

validate cells with dates in C#

Writing of the code to validate cells with dates in C# can be done by developers of any level using ByteScout Spreadsheet SDK. ByteScout Spreadsheet SDK was made to help with validate cells with dates in C#. ByteScout Spreadsheet SDK is the SDK that can write and read, modify and calculate Excel and CSV spreadsheets. Most popular formulas are supported. You may import or export data to and from CSV, XML, JSON as well as to and from databases, arrays.

The SDK samples like this one below explain how to quickly make your application do validate cells with dates in C# with the help of ByteScout Spreadsheet SDK. To do validate cells with dates in your C# project or application you may simply copy & paste the code and then run your app! You can use these C# sample examples in one or many applications.

Free trial version of ByteScout Spreadsheet SDK is available on our website. Get it to try other samples for C#.

Try ByteScout Spreadsheet SDK today: Get 60 Day Free Trial or sign up for Web API

Program.cs
      
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using Bytescout.Spreadsheet; using System.IO; namespace HelloWorld { class Program { static void Main(string[] args) { // in this sample we scan cells with ages data for people // then mark all dates where age is between 10 and 19 years and mark these cells with red color // Create new Spreadsheet Spreadsheet document = new Spreadsheet(); document.LoadFromFile("Data.xls"); // Get worksheet by name Worksheet worksheet = document.Workbook.Worksheets.ByName("Sample"); // Years range int RangeMin = 10; int RangeMax = 19; // Minimum age DateTime YearMin = DateTime.Now; // Maximum age DateTime YearMax = DateTime.Now; // Minimum year YearMax = YearMax.AddYears(-RangeMin); // Maximum year YearMin = YearMin.AddYears(-RangeMax); // Check dates for (int i = 1; i < 8; i++) { // Set current cell Cell currentCell = worksheet.Cell(i, 1); DateTime dateBirth = currentCell.ValueAsDateTime; // Check current cell if (dateBirth < YearMin || dateBirth > YearMax) { // Set fill pattern currentCell.FillPattern = Bytescout.Spreadsheet.Constants.PatternStyle.Solid; // Markup wrong cell by red color currentCell.FillPatternForeColor = System.Drawing.Color.Red; } // Set cell format currentCell.NumberFormatString = "dd.mm.yyyy"; } // delete output file if exists already if (File.Exists("Output.xls")){ File.Delete("Output.xls"); } // Save document document.SaveAs("Output.xls"); // Close Spreadsheet document.Close(); // open generated XLS document in default program Process.Start("Output.xls"); } } }

Try ByteScout Spreadsheet SDK today: 60 Day Free Trial (on-premise version) or sign up for Web API (on demand version)

VIDEO

ON-PREMISE VERSION

Get 60 Day Free Trial or Visit ByteScout Spreadsheet SDK page

Explore ByteScout Spreadsheet SDK documentation

WEB API

Sign Up for free Web API key

Explore Web API Documentation

Tutorials:

prev
next