How to set cell alignment in excel XLS document made with Bytescout Spreadsheet SDK 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 Spreadsheet SDK 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.Spreadsheet;
using System.Diagnostics;

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

// 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 Spreadsheet.Constants.HorAlignment.Centred;

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

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

worksheet.Cell(“B2”).Value = “Homer Jay Simpson”;
// setting justified alignment for the cell
worksheet.Cell(“B2”).HAlignment = Bytescout Spreadsheet.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)