Word .NET庫(kù)組件Spire.Doc系列教程(47):添加多行文字水印到 Word 文檔
Spire.Doc for .NET是一個(gè)專(zhuān)業(yè)的Word .NET庫(kù),設(shè)計(jì)用于幫助開(kāi)發(fā)人員高效地開(kāi)發(fā)創(chuàng)建、閱讀、編寫(xiě)、轉(zhuǎn)換和打印任何來(lái)自.NET( C#, VB.NET, ASP.NET)平臺(tái)的Word文檔文件的功能。
本系列教程將為大家?guī)?lái)Spire.Doc for .NET在使用過(guò)程中的各類(lèi)實(shí)際操作,本文將介紹如何使用Spire.Doc for .NET比較兩個(gè)Word文檔的內(nèi)容差異。
點(diǎn)擊下載Spire.Doc for .NET最新版
通常情況下,Microsoft word只支持添加一個(gè)文本水印到Word文檔。該文將介紹如何使用Spire.Doc for .NET 在Word文檔中頁(yè)眉中添加藝術(shù)字模擬實(shí)現(xiàn)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"); //添加藝術(shù)字并設(shè)置大小 ShapeObject shape = new ShapeObject(doc,ShapeType.TextPlainText); shape.Width = 60; shape.Height = 20; //設(shè)置藝術(shù)字文本內(nèi)容、位置及樣式 shape.VerticalPosition = 30; shape.HorizontalPosition = 20; shape.Rotation = 315; shape.WordArt.Text = "內(nèi)部使用"; 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的頁(yè)眉 header = section.HeadersFooters.Header; Paragraph paragraph1; for (int i = 0; i < 3; i++) { //添加段落到頁(yè)眉 paragraph1 = header.AddParagraph(); for (int j = 0; j < 4; j++) { //復(fù)制藝術(shù)字并設(shè)置多行多列位置 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 = "內(nèi)部使用" 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
多行多列文本水印效果圖:
推薦閱讀:【想要快速完成文檔格式轉(zhuǎn)換嗎?Spire系列組件格式轉(zhuǎn)換完整攻略來(lái)啦!】
還想要更多嗎?您可以點(diǎn)擊閱讀【2020 · E-iceblue最新資源整合】,查找需要的教程資源。如果您有任何疑問(wèn)或需求,請(qǐng)隨時(shí)聯(lián)系慧都客服,我們很高興為您提供查詢(xún)和咨詢(xún)。