"Serial" aspose.words inserting document elements using tutorials (i)

Source: Internet
Author: User

1. Insert a string of text:

the string that is inserted into the text needs to be inserted into the document via the Documentbuilder.write method. the text format is determined by the font properties, which contain different font attributes (font name, font size, color, and so on).

Some important font properties are also allowed by the [{{Documentbuilder}}] property to access them directly. These are Boolean properties [{{Font.bold}}],[{{font]. Italic}}], and [{{font.underline}}].

Note the character formatting will apply to all inserted text.

Example

Inserting formatted text using Documentbuilder

Documentbuilder builder = new Documentbuilder ();//Specify font formatting before adding text. Aspose.Words.Font Font = Builder. Font;font. Size = 16;font. Bold = True;font. Color = Color.blue;font. Name = "Arial"; font. Underline = Underline.dash;builder. Write ("Sample text.");

Visual Basic

Dim Builder as New documentbuilder () ' Specify font formatting before adding text. Dim font as Aspose.Words.Font = Builder. Fontfont.size = 16font. Bold = Truefont.color = Color.Bluefont.Name = "Arial" font. Underline = Underline.Dashbuilder.Write ("Sample text.")

2. Insert a paragraph


Documentbuilder. Writeln can also add a paragraph by inserting a string of text. The current font format is also

stipulated by Documentbuilder. Font properties and the current paragraph format are determined by the Documentbuilder.paragraphformat property

Availability

Example

How to add a paragraph to a document


C#

Document doc = new document ();D ocumentbuilder builder = new Documentbuilder (doc);//Specify Font FORMATTINGASPOSE.WORDS.F ont font = builder. Font;font. Size = 16;font. Bold = True;font. Color = System.drawing.color.blue;font. Name = "Arial"; font. Underline = underline.dash;//Specify paragraph formattingparagraphformat paragraphformat = Builder. Paragraphformat;paragraphformat.firstlineindent = 8;paragraphformat.alignment = paragraphalignment.justify; Paragraphformat.keeptogether = True;builder. Writeln ("A whole paragraph.");

Visual Basic

Dim doc As New Document () Dim builder As New Documentbuilder (DOC) ' Specify font formattingdim font as Aspose.Words.Font = b Uilder. Fontfont.size = 16font. Bold = Truefont.color = System.Drawing.Color.Bluefont.Name = "Arial" font. underline = Underline.dash ' Specify paragraph Formattingdim paragraphformat as ParagraphFormat = Builder. Paragraphformatparagraphformat.firstlineindent = 8paragraphformat.alignment = ParagraphAlignment.JustifyparagraphFormat.KeepTogether = Truebuilder.writeln ("A whole paragraph.")
3. Insert a table

The basic algorithm for creating a table using Documentbuilder is very simple:

1. Start the table with [{{documentbuilder.starttable}}];

2. Insert a cell using [{{Documentbuilder.insertcell}}], which automatically generates a new row and, if necessary, use [{{Documentbuilder]. CellFormat}}] property to specify the cell format;

3. Write cell contents using Documentbuilder.methods;

4. Repeat steps 2 and 3 until the contents of the line are finished;

5. Call [{{Documentbuilder]. Endrow}}] To end the current row and, if necessary, use the [{{DOCUMENTBUILDER.ROwformat}}] property to specify the row format ;

6. Repeat step 2-5 until the table is complete;

7. Call [{{Documentbuilder]. endtable}}] To complete the creation of the table.

Example

How to create a formatted table with 2 rows and 2 columns:


C#

Document doc = new document ();D ocumentbuilder builder = new  Documentbuilder (DOC); Table table = builder. Starttable ();// insert a cellbuilder. InsertCell ();// use fixed column widths.table.autofit (autofitbehavior.fixedcolumnwidths); Builder. Cellformat.verticalalignment = cellverticalalignment.center;builder. Write ("this is row 1 cell 1");// insert a cellbuilder. InsertCell (); builder. Write ("this is row 1 cell 2"); builder. Endrow ();// insert a cellbuilder. InsertCell ();// apply new row formattingbuilder. Rowformat.height = 100;builder. Rowformat.heightrule = heightrule.exactly;builder. Cellformat.orientation = textorientation.upward;builder. Writeln ("this is row 2 cell 1");// insert a cellbuilder. InsertCell (); builder. Cellformat.orientAtion = textorientation.downward;builder. Writeln ("this is row 2 cell 2"); builder. Endrow (); builder. Endtable ();


  Visual Basic

Dim doc as new document () Dim builder as new documentbuilder (DOC) Dim  table as table = builder. Starttable () '  insert a cellbuilder. InsertCell () '  use fixed column widths.table.autofit (autofitbehavior.fixedcolumnwidths) Builder. Cellformat.verticalalignment = cellverticalalignment.centerbuilder.write ("This is row  1 cell 1 ") '  insert a cellbuilder. InsertCell () builder. Write ("this is row 1 cell 2") builder. Endrow () '  insert a cellbuilder. InsertCell () '  apply new row formattingbuilder. Rowformat.height = 100builder. rowformat.heightrule = heightrule.exactlybuilder.cellformat.orientation =  TextOrientation.Upwardbuilder.Writeln ("this is row 2 cell 1") '  insert a  cellbuilder. InsertCell () builder. Cellformat.orientation = teXtOrientation.Downwardbuilder.Writeln ("this is row 2 cell 2") builder. Endrow () builder. Endtable ()
aspose.words Latest Version free download

"Serial" aspose.words inserting document elements using tutorials (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.