How to read date values from cells in existing XLS document using Bytescout Spreadsheet for .NET - ByteScout

How to read date values from cells in existing XLS document using Bytescout Spreadsheet for .NET

  • Home
  • /
  • Articles
  • /
  • How to read date values from cells in existing XLS document using Bytescout Spreadsheet for .NET

How to use Bytescout Spreadsheet to read date (datetime) values cells in existing XLS spreadsheet document

This source code sample demonstrates how to read datetime date values from cells in existing Excel spreadsheet (XLS) file with Bytescout Spreadsheet SDK for .NET

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

Screenshot of console output while reading datetime values from cells from existing XLS spreadsheet:

Reading values from spreadsheet and writing them into the console output

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(“Sample.xls”);

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

// Check dates
for (int i = 0; i < 4; i++)
{
// Set current cell
Cell currentCell = worksheet.Cell(i, 0);

// Get days
double days = System.Convert.ToDouble(currentCell.Value);

// Convert to DateTime
DateTime date = DateTime.FromOADate(days);

// Write Date
Console.WriteLine(“{0}”, date.ToShortDateString());
}

// Close document
document.Close();

// Write message
Console.Write(“Press any key to continue…”);

// Wait for user input
Console.ReadKey();

}
}
}

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

Tutorials:

prev
next