Have you ever seen the rainbow in clear sky? They look colorful and charming, but they are so far that we cannot touch it. Even so, we can make our life look as colorful as the rainbow. Just imagine, if all the one style black words you face every day become different in font and color, what you would feel. Isn’t it interesting? Your feeling maybe like the feeling of people in the 1970s who first saw the color TV. Word font and color can give an impressive effect to people as well as make some important information outstanding and easily found. They are very helpful in people’s work. This document aims at telling you how to operate this function well in Spire Doc. But first, let’s know a little information of Spire Doc.
Spire Doc,as a powerful MS word component, allows its users to perform various functions directly without Microsoft Word. It can effectively generate, read, write and modify Word document for .net and Silverlight. Using Spire.Doc, people can simply set word and font with C#,VB.NET.
Freely Download Spire.Doc
Procedure
Spire Doc,as a powerful MS word component, allows its users to perform various functions directly without Microsoft Word. It can effectively generate, read, write and modify Word document for .net and Silverlight. Using Spire.Doc, people can simply set word and font with C#,VB.NET.
Freely Download Spire.Doc
Procedure
First, Open Visual Studio (2008 or later)--File--New Project--Visual C# -- Console Application. Name Console Application Word Font and Color (If you want to create a Visual Basic project, Console Application, you can name the project Word Font and Color)—OK.
Second, Open Solution Explorer—Click project —Add Reference—Find "C:\Program Files\e-iceblue\Spire.Doc"(the default folder which you installed the Spire Doc in )— Double-click the folder Bin.
If the target framework of the project
Net 2.0, double-click folder NET2.0
or Net 3.5, double-click folder NET3.5
or Net 4.0, double-click folder NET4.0
Select assembly Spire Doc dll —Click OK
If the target framework of the project
Net 2.0, double-click folder NET2.0
or Net 3.5, double-click folder NET3.5
or Net 4.0, double-click folder NET4.0
Select assembly Spire Doc dll —Click OK
Third, after you create the Project Word Font and Color, you can see the code view and the following method has been added automatically:
C#
static void Main(string[] args)
C#
static void Main(string[] args)
Fourth, Project—Add Reference—Recent—System Drawing—OK.
Fifth, add the following codes to the top of the file:
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
Sixth, add the following codes to the method.
//Create word document
Document document = new Document();
//Create a new secition
Section section = document.AddSection();
//Create a new paragraph
Paragraph paragraph = section.AddParagraph();
//Append Text
String text
= "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. ";
TextRange txtRange = paragraph.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.SaveToFile("Sample.doc",FileFormat.Doc);
//Create word document
Document document = new Document();
//Create a new secition
Section section = document.AddSection();
//Create a new paragraph
Paragraph paragraph = section.AddParagraph();
//Append Text
String text
= "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. ";
TextRange txtRange = paragraph.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.SaveToFile("Sample.doc",FileFormat.Doc);
Finally, in Solution Explorer, right-click the project Word Font and Color—Click Debug—Start new instance, you can check the result in the project Word Font and Color, Word Indent—Bin—Debug —Sample. Look at picture 7.1:
Picture 7.1 shows us the color of the sky, from the above text, you can also see the font name, size and underline style of the paragraph, which give people some difference in sight.
Using Word Font and Color function, people would never worry that their documents are dull. Word document is just like a house needing us to decorate, Word Font and Color function, like various flowers, can ornament your document in an attracted way. Thus, your work not only can take happiness to other people, but also make yourself feel life is as colorful as the rainbow in the sky. Of course, there are many other practical functions of Word Font and Color, such as, marking the significant information, suiting the definite situation and so on. After we watch the color TV, I believe no one want to watch the black-and white color TV any more. The same case must be true, Word Font and Color can make our text look amazing, why don’t we use them? If you encounter problems in using the above code, please leave your questions in the Word Forum.
Word Forum
Using Word Font and Color function, people would never worry that their documents are dull. Word document is just like a house needing us to decorate, Word Font and Color function, like various flowers, can ornament your document in an attracted way. Thus, your work not only can take happiness to other people, but also make yourself feel life is as colorful as the rainbow in the sky. Of course, there are many other practical functions of Word Font and Color, such as, marking the significant information, suiting the definite situation and so on. After we watch the color TV, I believe no one want to watch the black-and white color TV any more. The same case must be true, Word Font and Color can make our text look amazing, why don’t we use them? If you encounter problems in using the above code, please leave your questions in the Word Forum.
Word Forum