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 set cell alignment in excel XLS document made with Bytescout.XLS library for .NET in C#

This source code sample demonstrates how to set and use different alignments (left, right, center) for a cell in xls documents generated with with Bytescout.XLS library for .NET

Download example source code: bytescoutxls_write_formula_into_cell.zip (1 KB)

using System;
using System.Collections.Generic;
using System.Text;
using Bytescout.XLS;
using System.Diagnostics;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
// Create new XLSDocument
XLSDocument document = new XLSDocument();

// Add new worksheet
Worksheet worksheet = document.WorkBook.Worksheets.Add("AlignmentDemo");

// Set Values
worksheet.Cell("A1").Value = "Name";
// setting centered alignment for the cell
worksheet.Cell("A1").HAlignment = Bytescout.XLS.Constants.HorAlignment.Centred;

worksheet.Cell("B1").Value = "Full Name";
// setting centered alignment for the cell
worksheet.Cell("B1").HAlignment = Bytescout.XLS.Constants.HorAlignment.Centred;

worksheet.Cell("A2").Value = "Homer";
// setting justifiedalignment for the cell
worksheet.Cell("A2").HAlignment = Bytescout.XLS.Constants.HorAlignment.Right;

worksheet.Cell("B2").Value = "Homer Jay Simpson";
// setting justified alignment for the cell
worksheet.Cell("B2").HAlignment = Bytescout.XLS.Constants.HorAlignment.Right;

// set columns width
worksheet.Columns[0].Width = 300; // A column
worksheet.Columns[1].Width = 400; // B column

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

// open XLS document in default XLS Excel documents application
Process.Start("CellAlignment.xls");
}
}
}

Download example source code: bytescoutxls_write_formula_into_cell.zip (1 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