文檔首頁>>Aspose中文文檔>>插入表格
插入表格
Aspose.Words是一種高級Word文檔處理API,用于執(zhí)行各種文檔管理和操作任務(wù)。API支持生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔,而無需在跨平臺應(yīng)用程序中直接使用Microsoft Word。
Aspose API支持流行文件格式處理,并允許將各類文檔導(dǎo)出或轉(zhuǎn)換為固定布局文件格式和最常用的圖像/多媒體格式。
VSTOWord.Application wordApp = Application; wordApp.Documents.Open("Inserting Table.doc"); CreateDocumentPropertyTable(); this.Application.ActiveDocument.Save(); private void CreateDocumentPropertyTable() { object start = 0, end = 0; Word.Range rng = this.Application.ActiveDocument.Range(ref start, ref end); // Insert a title for the table and paragraph marks. rng.InsertBefore("Document Statistics"); rng.Font.Name = "Verdana"; rng.Font.Size = 16; rng.InsertParagraphAfter(); rng.InsertParagraphAfter(); rng.SetRange(rng.End, rng.End); // Add the table. rng.Tables.Add(this.Application.ActiveDocument.Paragraphs[2].Range, 3, 2, ref missing, ref missing); // Format the table and apply a style. Word.Table tbl = this.Application.ActiveDocument.Tables[1]; tbl.Range.Font.Size = 12; tbl.Columns.DistributeWidth(); object styleName = "Table Professional"; tbl.set_Style(ref styleName); // Insert document properties into cells. tbl.Cell(1, 1).Range.Text = "Document Property"; tbl.Cell(1, 2).Range.Text = "Value"; tbl.Cell(2, 1).Range.Text = "Subject"; tbl.Cell(2, 2).Range.Text = ((Office.DocumentProperties)(this.Application.ActiveDocument.BuiltInDocumentProperties)) [Word.WdBuiltInProperty.wdPropertySubject].Value.ToString(); tbl.Cell(3, 1).Range.Text = "Author"; tbl.Cell(3, 2).Range.Text = ((Office.DocumentProperties)(this.Application.ActiveDocument.BuiltInDocumentProperties)) [Word.WdBuiltInProperty.wdPropertyAuthor].Value.ToString(); }
點擊復(fù)制
Aspose.Words
Document doc = new Document("Inserting Table.doc"); 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("Inserting Table.doc");
點擊復(fù)制
下載示例代碼