Aspose.words is a powerful Word document processing control that allows word creation, modification, conversion, and more, without the need to install Word.
Aspose.words can simply insert a Word table using the Documentbuilder class library provided by the product.
Documentbuilder.starttable to start building a new table
Documentbuilder.insertcell inserting new rows and cells into a table
Documentbuilder.writeln writing text for the current cell
Documentbuilder.endrow used to indicate the end of the current line and start a new row
Documentbuilder.endtable indicates that the table build is complete
The following code shows how to insert a simple unformatted table into Word:
Document doc = new document ();
Documentbuilder builder = new Documentbuilder (DOC);
We call this method to start building the table.
Builder. Starttable ();
Builder. InsertCell ();
Builder. Write ("Row 1, Cell 1 Content.");
Build the second cell
Builder. InsertCell ();
Builder. Write ("Row 1, Cell 2 Content.");
Call the following method to end the row and start a new row.
Builder. Endrow ();
Build the first cell of the second row.
Builder. InsertCell ();
Builder. Write ("Row 2, Cell 1 Content");
Build the second cell.
Builder. InsertCell ();
Builder. Write ("Row 2, Cell 2 Content.");
Builder. Endrow ();
Signal that we have finished building the table.
Builder. Endtable ();
Save the document to disk.
Doc. Save (MyDir + "documentbuilder.createsimpletable out.doc");
The following code shows how to insert a formatted table into Word using code:
Document doc = new document ();
Documentbuilder builder = new Documentbuilder (DOC);
Table table = Builder. Starttable ();
Make the header row.
Builder. InsertCell ();
Set the left indent for the table. Table wide formatting must be applied after
At least one row are present in the table.
Table. LeftIndent = 20.0;
Set height and define the height rule for the header row.
Builder. Rowformat.height = 40.0;
Builder. Rowformat.heightrule = Heightrule.atleast;
Some Special features for the header row.
Builder. CellFormat.Shading.BackgroundPatternColor = Color.FromArgb (198, 217, 241);
Builder. ParagraphFormat.Alignment = Paragraphalignment.center;
Builder. Font.Size = 16;
Builder. Font.Name = "Arial";
Builder. Font.Bold = true;
Builder. Cellformat.width = 100.0;
Builder. Write ("Header row,\n Cell 1");
We don ' t need to specify the width of this cell because it's inherited from the previous cell.
Builder. InsertCell ();
Builder. Write ("Header row,\n Cell 2");
Builder. InsertCell ();
Builder. Cellformat.width = 200.0;
Builder. Write ("Header row,\n Cell 3");
Builder. Endrow ();
Set features for the other rows and cells.
Builder. CellFormat.Shading.BackgroundPatternColor = Color.White;
Builder. Cellformat.width = 100.0;
Builder. Cellformat.verticalalignment = Cellverticalalignment.center;
Reset height and define a different height rule for table body
Builder. Rowformat.height = 30.0;
Builder. Rowformat.heightrule = Heightrule.auto;
Builder. InsertCell ();
Reset font formatting.
Builder. Font.Size = 12;
Builder. Font.Bold = false;
Build the other cells.
Builder. Write ("Row 1, Cell 1 Content");
Builder. InsertCell ();
Builder. Write ("Row 1, Cell 2 Content");
Builder. InsertCell ();
Builder. Cellformat.width = 200.0;
Builder. Write ("Row 1, Cell 3 Content");
Builder. Endrow ();
Builder. InsertCell ();
Builder. Cellformat.width = 100.0;
Builder. Write ("Row 2, Cell 1 Content");
Builder. InsertCell ();
Builder. Write ("Row 2, Cell 2 Content");
Builder. InsertCell ();
Builder. Cellformat.width = 200.0;
Builder. Write ("Row 2, Cell 3 Content.");
Builder. Endrow ();
Builder. Endtable ();
Doc. Save (MyDir + "documentbuilder.createformattedtable out.doc");
Beta Download: http://www.componentcn.com/html/wbbjkj_281_3926.html
Contact information: 846631466