How to use different fonts for cells in spreadsheets made with Bytescout Spreadsheet for .NET - ByteScout

How to use different fonts for cells in spreadsheets made with Bytescout Spreadsheet for .NET

  • Home
  • /
  • Articles
  • /
  • How to use different fonts for cells in spreadsheets made with Bytescout Spreadsheet for .NET

How to use different fonts for cells in spreadsheet Excel XLS documents generates with Bytescout Spreadsheet SDK

This source code sample demonstrates how to set different font names for cells in spreadsheet and Excel documents generated by Bytescout Spreadsheet for .NET

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

Sample spreadsheet (XLS document) screenshot:

Times New Roman and other fonts in generated spreadsheet

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

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(“HelloWorld”);

// Create array with font names
string[] fontNames = new string[] {
“Helvetica”,
“Times New Roman”,
“Verdana”,
“Times New Roman”
};

// Use all fonts in fontsNames array
for (int i = 0; i < fontNames.Length; i++)
{
// Set font size based on loop counter
float fontSize = 10 + i * 3;

//Set cell font type and font size
worksheet.Cell(i, 0).Font = new System.Drawing.Font(fontNames[i], fontSize);

// Set cell value
worksheet.Cell(i, 0).Value = fontNames[i];
}

// Save document
document.SaveAs(“Fonts.xls”);

// Close document
document.Close();

// open generated XLS document in default program
Process.Start(“Fonts.xls”);
}
}
}

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

Tutorials:

prev
next