This example demonstrates how to specify font formatting.
[C#]
using System;
using NativeExcel;
class Program {
static void Main(string[] args) {
//Create a new empty workbook.
IWorkbook book = NativeExcel.Factory.CreateWorkbook();
//Create a new sheet in the workbook.
IWorksheet sheet = book.Worksheets.Add();
//Set a value for cell A2
sheet.Cells["A2"].Value = 300; //number value
//Set a value for cell B2
sheet.Cells["B2"].Value = "Text value"; //text value
//Get IFont interface for the range A2:F2
IFont font = sheet.Cells["A2:F2"].Font;
//Change font settings
font.Name = "Times New Roman";
font.Size = 15;
font.Bold = true;
//Change format of the cell D2 to italic
sheet.Cells["D2"].Font.Italic = true;
//Save workbook
book.SaveAs("book.xls");
}
}
[Visual Basic]
Imports System
Imports NativeExcel
Public Module Program
Sub Main()
'Create a new empty workbook.
Dim book As IWorkbook = NativeExcel.Factory.CreateWorkbook()
'Create a new sheet in the workbook.
Dim sheet As IWorksheet = book.Worksheets.Add()
'Set a value for cell A2
sheet.Cells("A2").Value = 300 'number value
'Set a value for cell B2
sheet.Cells("B2").Value = "Text value" 'text value
'Get IFont interface for the range A2:F2
Dim font As IFont = sheet.Cells("A2:F2").Font
'Change font settings
font.Name = "Times New Roman"
font.Size = 15
font.Bold = True
'Change format of the cell D2 to italic
sheet.Cells("D2").Font.Italic = True
'Save workbook
book.SaveAs("book.xls")
End Sub
End Module
[C++]
#using <System.dll>
using namespace System;
#using <NativeExcel.dll>
using namespace NativeExcel;
int main() {
//Create a new empty workbook.
IWorkbook* book = NativeExcel::Factory::CreateWorkbook();
//Create a new sheet in the workbook.
IWorksheet* sheet = book->Worksheets->Add();
//Set a value for cell A2
sheet->Cells->Item[S"A2"]->Value = 300; //number value
//Set a value for cell B2
sheet->Cells->Item[S"B2"]->Value = S"Text value"; //text value
//Get IFont interface for the range A2:F2
IFont* font = sheet->Cells->Item[S"A2:F2"]->Font;
//Change font settings
font->Name = "Times New Roman";
font->Size = 15;
font->Bold = true;
//Change format of the cell D2 to italic
sheet->Cells->Item[S"D2"]->Font->Italic = true;
//Save workbook
book->SaveAs(S"book.xls");
return 0;
} // end main