Home

Bytescout.XLS for .NET
Screenshots

Click to view sample
Click to view sample
Click to view sample
Click to view sample
Click to view sample
Click to view sample
Click to view sample Click to view sample

Bytescout.XLS library for .NET

Download Free Trial Buy Now More Information

How to format cell to display formatted date time value in XLS spreadsheet generated/modified with using Bytescout.XLS library

This source code sample demonstrates how to format date value in cell in spreadsheet using Bytescout.XLS for .NET applications

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

Output spreadsheet (XLS) screenshot:

Values with date formatted in spreadsheet

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();

// Get worksheet by name
Worksheet worksheet = document.WorkBook.Worksheets.Add("Sample");

// Set captions
worksheet.Cell(0, 0).Value = "#";
worksheet.Cell(0, 1).Value = "Date";

for (int i = 1; i < 8; i++)
{
// Set number
worksheet.Cell(i, 0).Value = i;

// Set current cell
Cell currentCell = worksheet.Cell(i, 1);

// Set date. This is days since 01.01.1900
// You can also convert number to date time using the function: DateTime.FromOADate(double d)
currentCell.Value = 30000 + i * 1000;

// Set date format
currentCell.NumberFormat = "dd.mm.yyyy";
}

// Save document
document.SaveAs("Sample.xls");

// Close document
document.Close();

// open generated XLS document in default program
Process.Start("Sample.xls");
}
}
}

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

Download Free Trial Buy Now More Information

Documentation online: view (separate window)

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