翻譯|使用教程|編輯:李顯亮|2020-09-08 09:56:01.700|閱讀 480 次
概述:該文將介紹如何使用Spire.Doc for .NET 在Word文檔中頁眉中添加藝術字模擬實現Word文檔中多行文字水印效果。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一個專業的Word .NET庫,設計用于幫助開發人員高效地開發創建、閱讀、編寫、轉換和打印任何來自.NET( C#, VB.NET, ASP.NET)平臺的Word文檔文件的功能。
本系列教程將為大家帶來Spire.Doc for .NET在使用過程中的各類實際操作,本文將介紹如何使用Spire.Doc for .NET比較兩個Word文檔的內容差異。
通常情況下,Microsoft word只支持添加一個文本水印到Word文檔。該文將介紹如何使用Spire.Doc for .NET 在Word文檔中頁眉中添加藝術字模擬實現Word文檔中多行文字水印效果。
C#
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; namespace WordWatermark { class Program { static void Main(string[] args) { //加載示例文檔 Document doc = new Document(); doc.LoadFromFile("Sample.docx"); //添加藝術字并設置大小 ShapeObject shape = new ShapeObject(doc,ShapeType.TextPlainText); shape.Width = 60; shape.Height = 20; //設置藝術字文本內容、位置及樣式 shape.VerticalPosition = 30; shape.HorizontalPosition = 20; shape.Rotation = 315; shape.WordArt.Text = "內部使用"; shape.FillColor = System.Drawing.Color.Red; shape.StrokeColor = System.Drawing.Color.Gray; Section section; HeaderFooter header; for (int n = 0; n < doc.Sections.Count; n++) { section = doc.Sections[n]; //獲取section的頁眉 header = section.HeadersFooters.Header; Paragraph paragraph1; for (int i = 0; i < 3; i++) { //添加段落到頁眉 paragraph1 = header.AddParagraph(); for (int j = 0; j < 4; j++) { //復制藝術字并設置多行多列位置 shape = (ShapeObject)shape.Clone(); shape.VerticalPosition = 50 + 150 * i; shape.HorizontalPosition=20 + 160 * j; paragraph1.ChildObjects.Add(shape); } } } //保存文檔 doc.SaveToFile("result.docx", FileFormat.Docx2013); System.Diagnostics.Process.Start("result.docx"); } } }
VB.NET
Class Program Private Shared Sub Main(ByVal args As String()) Dim doc As Document = New Document() doc.LoadFromFile("Sample.docx") Dim shape As ShapeObject = New ShapeObject(doc, ShapeType.TextPlainText) shape.Width = 60 shape.Height = 20 shape.VerticalPosition = 30 shape.HorizontalPosition = 20 shape.Rotation = 315 shape.WordArt.Text = "內部使用" shape.FillColor = System.Drawing.Color.Red shape.StrokeColor = System.Drawing.Color.Gray Dim section As Section Dim header As HeaderFooter For n As Integer = 0 To doc.Sections.Count - 1 section = doc.Sections(n) header = section.HeadersFooters.Header Dim paragraph1 As Paragraph For i As Integer = 0 To 3 - 1 paragraph1 = header.AddParagraph() For j As Integer = 0 To 4 - 1 shape = CType(shape.Clone(), ShapeObject) shape.VerticalPosition = 50 + 150 * i shape.HorizontalPosition = 20 + 160 * j paragraph1.ChildObjects.Add(shape) Next Next Next doc.SaveToFile("result.docx", FileFormat.Docx2013) End Sub End Class
多行多列文本水印效果圖:
推薦閱讀:【想要快速完成文檔格式轉換嗎?Spire系列組件格式轉換完整攻略來啦!】
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn