Home

Bytescout.XLS for .NET

Click to view full size screenshot

Bytescout.XLS library for .NET

Download Free Trial Buy Now More Information

How to use Bytescout.XLS 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.XLS library 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.XLS;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
// Create new XLSDocument
XLSDocument document = new XLSDocument("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)

Download Free Trial Buy Now More Information

First steps tutorials:

Advanced Examples:
Products  |  Download  |  Purchase  |  Support  |  Contacts  |  Testimonials |  

ByteScout, 2003-2008. All other company and product names may be trademarks of their respective companies. Privacy Statement