Aspose.Words使用教程之插入文件元素(一)
1.插入文字的字串:
插入文字的字串需要通過DocumentBuilder.Write
方法插入到文件。文字格式是由字型屬性決定,這個物件包含不同的字型屬性(字型名稱,字型大小,顏色,等等)。
一些重要的字型屬性也由[{ { DocumentBuilder } }]
屬性允許您直接訪問它們。這些都是布林屬性[{{Font.Bold}}],[{{Font.Italic}}], and [{{Font.Underline}}]
。
注意字元格式設定將適用於所有插入的文字。
Example
使用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.");
2.插入一個段落
DocumentBuilder.Writeln
可以插入一段文字的字串也能新增一個段落。當前字型格式也是由DocumentBuilder
所規定。字型屬性和當前段落格式是由DocumentBuilder.ParagraphFormat
屬性所決定。
Example
如何新增一個段落到文件
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Specify font formatting
Aspose.Words.Font font = builder.Font;
font.Size = 16;
font.Bold = true;
font.Color = System.Drawing.Color.Blue;
font.Name = "Arial";
font.Underline = Underline.Dash;
// Specify paragraph formatting
ParagraphFormat paragraphFormat = builder.ParagraphFormat;
paragraphFormat.FirstLineIndent = 8;
paragraphFormat.Alignment = ParagraphAlignment.Justify;
paragraphFormat.KeepTogether = true;
builder.Writeln("A whole paragraph.");
3.插入一張表
使用DocumentBuilder
建立一個表的基本演算法是非常簡單的:
1.使用[{{DocumentBuilder.StartTable}}]
啟動表;
2.使用[{{DocumentBuilder.InsertCell}}]
插入單元格,這自動生成一個新行,如果需要,使用 [{{DocumentBuilder.CellFormat}}]
屬性來指定單元格格式;
3.使用DocumentBuilder.methods
寫入單元格內容;
4.重複步驟2和3,直到行內容寫完;
5.呼叫[{{DocumentBuilder.EndRow}}]
來結束當前的行,如果需要,使用[{ { DocumentBuilder.RowFormat }}]
屬性來指定行格式;
6.重複步驟2 - 5直到表完成;
7.呼叫[{{DocumentBuilder.EndTable}}]
來完成表的建立。
Example
如何建立一個2行2列的格式化表格:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Table table = builder.StartTable();
// Insert a cell
builder.InsertCell();
// Use fixed column widths.
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.Write("This is row 1 cell 1");
// Insert a cell
builder.InsertCell();
builder.Write("This is row 1 cell 2");
builder.EndRow();
// Insert a cell
builder.InsertCell();
// Apply new row formatting
builder.RowFormat.Height = 100;
builder.RowFormat.HeightRule = HeightRule.Exactly;
builder.CellFormat.Orientation = TextOrientation.Upward;
builder.Writeln("This is row 2 cell 1");
// Insert a cell
builder.InsertCell();
builder.CellFormat.Orientation = TextOrientation.Downward;
builder.Writeln("This is row 2 cell 2");
builder.EndRow();
builder.EndTable();
相關文章
- Aspose.Words使用教程之插入文件元素(二)
- Aspose.Words使用教程之插入文件元素(三)
- Aspose.Words使用教程之在文件中找到並替換文字
- 使用Aspose.Words元件進行word文件書籤替換,文件、圖表插入,轉pdf等元件
- Aspose.Words使用教程之如何操作主題屬性,如何在文件中新增水印
- Aspose.Words使用教程之從零在word裡建立OOXML圖表XML
- Aspose.Words使用教程之(如何使用ChartDataLabel),(如何重新命名合併欄位)
- JQuery插入元素jQuery
- li列表的前面插入一個元素
- HashMap之元素插入HashMap
- TreeMap之元素插入
- Aspose.Words使用教程之如何寫入純文字(TXT)檔案,表的合併與拆分
- JavaScript在指定元素後面插入元素JavaScript
- JavaScript 插入新li元素JavaScript
- MongoDB(7)- 文件插入操作MongoDB
- javascript如何在元素中插入新的元素JavaScript
- ul最後插入li元素
- js實現的在li元素列表的任意位置插入一個新的li元素JS
- JS 獲取文件元素JS
- 第 7 章 文件元素
- 如何將一個陣列中的元素插入另一個陣列陣列
- 文件驅動 —— 表單元件(一):表單元素元件元件
- JavaScript 陣列 指定索引位置插入元素JavaScript陣列索引
- AppleWatch開發教程之除錯程式使用幫助文件APP除錯
- ASPOSE.Cells & ASPOSE.Words 操縱Excel和Word文件的 .NET Core 例項Excel
- js 在陣列的指定索引位置插入一個新的元素JS陣列索引
- 在ul的最後插入一個li元素程式碼例項
- 在Excel表格中插入Word文件方法Excel
- MongoDB批量插入大資料文件的簡單方法一例MongoDB大資料
- oeasy教您玩轉vim - 9 - # 換行插入
- 二分搜尋樹元素的插入
- jQuery將li元素插入列表開頭jQuery
- JavaScript陣列指定位置插入新元素JavaScript陣列
- 如何將<img>圖片插入html元素中HTML
- 在JS陣列指定位置插入元素JS陣列
- arraylist陣列元素插入及顯示示例陣列
- aspose.words for java操作文件doc,設定一級二級三級標題以及段落表格等詳情Java
- 死磕 java集合之ConcurrentHashMap原始碼分析(一)——插入元素全解析JavaHashMap原始碼