Samples: Font

   Minimize
  Font Sample for C# / VB.NET


Download the sample here
 
[C#]
XlsDocumentBuilder builder = new XlsDocumentBuilder();
//create a workbook
IXlsWorkbook book = builder.Create(1);
//Add worksheet
IXlsWorksheet sheet = book.Worksheets[0];
IXlsRange range = sheet.Range["B2:F10"];
//Set value to "Text" for each cell in the range
range.Value2 = "Text";
//Set the font name and size
range.CellStyle.Font.Name = "Times New Roman";
range.CellStyle.Font.Size = 15;
//Set the font style to bold for the first row of the range
range.Rows[1].CellStyle.Font.Bold = true;
//Set the font style to italic for the first column of the range
range.Columns[1].CellStyle.Font.Italic = true;
//Set the font color for the second row of the range 
//range.Rows[2].CellStyle.Font.Color = Color.Red;
//Set the font color, size and underline for the third row
//of the range
//range.Rows[3].CellStyle.Font.Color = Color.Green;
range.Rows[3].CellStyle.Font.Size = 8;
range.Rows[3].CellStyle.Font.Underline = XlsUnderline.Single;
//Set the font name for the second column of the range
range.Columns[2].CellStyle.Font.Name = "Arial";
//Set the font size for the range E8:F10
sheet.Range["E8:F10"].CellStyle.Font.Size = 10;
//Set the font style to bold for the range E8:F10
sheet.Range["E8:F10"].CellStyle.Font.Bold = true;
//Set the borders style for the range E8:F10 
sheet.Range["E8:F10"].Borders.LineStyle = XlsLineStyle.Dotted;
//Save workbook
book.Save(FileName);
[VB.NET]
Dim builder As New XlsDocumentBuilder()
'create a workbook
Dim book As IXlsWorkbook = builder.Create(1)
'Add worksheet 
Dim sheet As IXlsWorksheet = book.Worksheets(0)
Dim range As IXlsRange = sheet.Range("B2:F10")
'Set value to "Text" for each cell in the range 
range.Value2 = "Text"
'Set the font name and size 
range.CellStyle.Font.Name = "Times New Roman"
range.CellStyle.Font.Size = 15
'Set the font style to bold for the first row of the range 
range.Rows(1).CellStyle.Font.Bold = True
'Set the font style to italic for the first column of the range 
range.Columns(1).CellStyle.Font.Italic = True
'Set the font color for the second row of the range 
'range.Rows[2].CellStyle.Font.Color = Color.Red;
'Set the font color, size and underline for the third row 
'of the range
'range.Rows[3].CellStyle.Font.Color = Color.Green;
range.Rows(3).CellStyle.Font.Size = 8
range.Rows(3).CellStyle.Font.Underline = XlsUnderline.[Single]
'Set the font name for the second column of the range 
range.Columns(2).CellStyle.Font.Name = "Arial"
'Set the font size for the range E8:F10 
sheet.Range("E8:F10").CellStyle.Font.Size = 10
'Set the font style to bold for the range E8:F10
sheet.Range("E8:F10").CellStyle.Font.Bold = True
'Set the borders style for the range E8:F10
sheet.Range("E8:F10").Borders.LineStyle = XlsLineStyle.Dotted
'Save workbook 
book.Save(FileName)