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 use cell format for numbers while writing spreadsheet document using Bytescout.XLS library

This source code sample demonstrates how to use different number formatting for cells in spreadsheet generated with Bytescout.XLS library

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

Generated spreadsheet screenshot:

Different number formats are shown in the generated 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 header
worksheet.Cell(0, 0).Value = "Number";
worksheet.Cell(0, 1).Value = "Format";

// Set variables
double plan = 3000;
double result = 3100;

// Fill cells
for (int i = 1; i < 6; i++)
{
worksheet.Cell(i, 0).Value = result / plan;
}

// Set cells format
worksheet.Cell(1, 0).NumberFormat = "0.00";
worksheet.Cell(2, 0).NumberFormat = "0.00%";
worksheet.Cell(3, 0).NumberFormat = "mm:ss";
worksheet.Cell(4, 0).NumberFormat = "hh:mm:ss";
worksheet.Cell(5, 0).NumberFormat = "##0,0E+0";

// Set captions
worksheet.Cell(1, 1).Value = "0.00";
worksheet.Cell(2, 1).Value = "0.00%";
worksheet.Cell(3, 1).Value = "mm:ss";
worksheet.Cell(4, 1).Value = "hh:mm:ss";
worksheet.Cell(5, 1).Value = "##0,0E+0";

// 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_number_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  |  News |  

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