Close





 
Tuesday, 05 April 2011 09:07

PDF Font C#, VB.NET

The sample demonstrates how to work with font in PDF document.

Download Font.pdf

Published in Formating
Wednesday, 05 January 2011 08:36

How to Use C#/VB.NET to Set Excel Font

In order to have a good-looking layout or emphasize some special and important data in Excel, we often need to set cell format. One part of cell format is font setting. Excel font setting is similar to Word, including font style, size, color and so on. People can set style or color according to their requirements. But it is usual to set title of one row or column as bold or larger size font.

How to Set Excel Font via Spire.XLS?

Actually, the action to C# Excel Font style is a process to assign the Excel Font properties values, which may be used depending on different requirements. For example, we may assign a value for Font.Color property to get desired color of specified contents in the worksheet.
Then, the following shows the method to set Excel font with C#/VB.NET via Spire.XLS.

Follow the Steps below:
  1. Download Spire.XLS and install it on your computer.
  2. Create a new console project and then add Spire.XLS DLL file in the project.
  3. Add another reference System.Drawing
  4. Assign Excel font properties values to set font, for example, we assign a value for Font.Color property to set the color we want.
Full C#/VB.NET Code to Set Excel Font:
[C#]
using System.Drawing;
using Spire.Xls;

namespace FontStyle
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a new workbook.
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];
            
            //Write text with the font of Arial.
            sheet.Range["B1"].Text = "Arial";
            sheet.Range["B1"].Style.Font.FontName = "Arial";
            
            //Write text with the font of Large size.
            sheet.Range["B2"].Text = "Large size";
            sheet.Range["B2"].Style.Font.Size = 20;
            
            //Write text with the font of Bold.
            sheet.Range["B3"].Text = "Bold";
            sheet.Range["B3"].Style.Font.IsBold = true;
            
            //Write text with the font of Italic.
            sheet.Range["B4"].Text = "Italic";
            sheet.Range["B4"].Style.Font.IsItalic = true;
            
            //Write text with the font of Superscript.
            sheet.Range["B5"].Text = "Superscript";
            sheet.Range["B5"].Style.Font.IsSuperscript = true;
            
            //Write text with the font of Colored.
            sheet.Range["B6"].Text = "Colored";
            sheet.Range["B6"].Style.Font.Color = Color.FromArgb(255, 125, 125);
            
            //Write text with the font of Underline.
            sheet.Range["B7"].Text = "Underline";
            sheet.Range["B7"].Style.Font.Underline = FontUnderlineType.Single;
            
            //Save the file.
            workbook.SaveToFile("Sample.xls");
            
            //Launch the file.
            System.Diagnostics.Process.Start("Sample.xls");
        }
    }
}
          
[Visual Basic]
Imports Microsoft.VisualBasic
Imports System.Drawing
Imports Spire.Xls

Module Module1

    Sub Main()
        'Create a new workbook.
        Dim workbook As Workbook = New Workbook()
        Dim sheet As Worksheet = workbook.Worksheets(0)
        
        'Write text with the font of Arial.
        sheet.Range("B1").Text = "Arial"
        sheet.Range("B1").Style.Font.FontName = "Arial"
        
        'Write text with the font of Large size.
        sheet.Range("B2").Text = "Large size"
        sheet.Range("B2").Style.Font.Size = 20
        
        'Write text with the font of Bold.
        sheet.Range("B3").Text = "Bold"
        sheet.Range("B3").Style.Font.IsBold = True
        
        'Write text with the font of Italic.
        sheet.Range("B4").Text = "Italic"
        sheet.Range("B4").Style.Font.IsItalic = True
        
        'Write text with the font of Superscript.
        sheet.Range("B5").Text = "Superscript"
        sheet.Range("B5").Style.Font.IsSuperscript = True
        
        'Write text with the font of Colored.
        sheet.Range("B6").Text = "Colored"
        sheet.Range("B6").Style.Font.Color = Color.FromArgb(255, 125, 125)
        
        'Write text with the font of Underline.
        sheet.Range("B7").Text = "Underline"
        sheet.Range("B7").Style.Font.Underline = FontUnderlineType.Single
        
        'Save the file.
        workbook.SaveToFile("Sample.xls")
        
        'Launch the file.
        System.Diagnostics.Process.Start("Sample.xls")
    End Sub
End Module
          
After running the demo, you may find different styles of font appear in the document:

Spire.XLS is a professional Excel component which enables developers/programmers to fast generate, read, write and modify Excel document for .NET and Silverlight. Click to learn more...
Published in Program Guide
Friday, 02 July 2010 23:37

EXCEL Font Styles for C#, VB.NET

 
 
The sample demonstrates how to set font formatting in an excel workbook.

FontStyles.gif

Published in Styles