Pregled posta

Adresa bloga: https://blog.dnevnik.hr/spireexcel

Marketing

A Brief Introduction about Word Font and How to Set with VB.NET

Microsoft Word is frequently used because it is powerful on dealing with word information, for example, we often use it to write announcements, papers and so on.

Someone may not set format for Word documents for the documents are draft. However, when we submit the documents or the contents in documents to website or print them, we need to pay attention on format setting, especially word font settings.

Open Microsoft Word, we can find that there are several tools on Toolbar for setting font styles. The frequently used styles include font type, size, color and bold, italic, underline.

Generally speaking, the title is often set as bold and the key words are given in obvious color. If we insert hyperlink, the words which insert link will be underlined automatically and usually, the color will turn in blue.

About font type, I would like to use Times New Roman. Arial is the default font type. Also, you can use other types. There are lots of font types which can be chosen in Microsoft Word.

For common users, they can set format directly. For programmers, they may use C# or VB.Net to operate Word. And I want to introduce a method about using VB.NET to set word font.

Note: .Net Framework and Spire.Doc should be installed.

'Create word document
Dim document_Renamed As New Document()
'Create a new secition
Dim section_Renamed As Section = document_Renamed.AddSection()
'Create a new paragraph
Dim paragraph_Renamed As Paragraph = section_Renamed.AddParagraph()
'Append Text
Dim text As String _
= "This paragraph is demo of text font and color. " _
& "The font name of this paragraph is Tahoma. " _
& "The font size of this paragraph is 20. " _
& "The under line style of this paragraph is DotDot. " _
& "The color of this paragraph is Blue. "
Dim txtRange As TextRange = paragraph_Renamed.AppendText(text)
'Font name
txtRange.CharacterFormat.FontName = "Tahoma"
'Font size
txtRange.CharacterFormat.FontSize = 20
'Underline
txtRange.CharacterFormat.UnderlineStyle = UnderlineStyle.DotDot
'Change text color
txtRange.CharacterFormat.TextColor = Color.Blue
'Save doc file.
document_Renamed.SaveToFile("Sample.doc",FileFormat.Doc)



Post je objavljen 17.03.2011. u 03:40 sati.