在 Word 中插入藝術字
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。在 C#、VB.NET 中從 Word 中提取圖像。
藝術字是 MS Word 中的一項功能,可讓您在文檔中插入色彩豐富且時尚的文本。除此之外,它還可以彎曲、拉伸或傾斜文本的形狀,這是一種通過特殊效果使文本脫穎而出的快速方法。在本文中,您將學習如何使用Spire.Doc for .NET以編程方式將藝術字插入 Word 文檔。
為 .NET 安裝 Spire.Doc
首先,您需要添加 Spire.Doc for .NET 包中包含的 DLL 文件作為 .NET 項目中的引用。DLL 文件可以從此鏈接下載或通過NuGet安裝。
PM> Install-Package Spire.Doc
在 Word 中插入藝術字
Spire.Doc 為 .NET 提供的ShapeType枚舉定義了各種名稱以“Text”開頭的藝術字形狀類型。為了在 Word 中創建藝術字,您需要初始化一個ShapeObject實例并指定藝術字類型和文本內容。詳細步驟如下:
- 創建一個文檔實例。
- 使用Document.AddSection()方法向文檔添加一個部分,然后使用Section.AddParagraph()方法向該部分添加一個段落。
- 將形狀附加到段落并使用Paragraph.AppendShape(float width , float height , ShapeType shapeType )方法指定形狀大小和類型。
- 使用ShapeObject.VerticalPosition和ShapeObject.HorizontalPosition屬性設置形狀的位置。
- 使用WordArt.Text屬性設置藝術字的文本。
- 使用ShapeObject.FillColor和ShapeObject.StrokeColor屬性設置藝術字的填充顏色和描邊顏色。
- 使用Document.SaveToFile()方法將文檔保存到另一個文件。
【C#】
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
namespace CreatWordArt
{
class Program
{
static void Main(string[] args)
{
//Create a Document instance
Document doc = new Document();
//Add a section
Section section = doc.AddSection();
//Add a paragraph
Paragraph paragraph = section.AddParagraph();
//Append a shape to the paragraph and specify the shape size and type
ShapeObject shape = paragraph.AppendShape(400, 150, ShapeType.TextDeflateBottom);
//Set the position of the shape
shape.VerticalPosition = 60;
shape.HorizontalPosition = 60;
//Set the text of WordArt
shape.WordArt.Text = "Create WordArt in Word";
//Set the fill color and stroke color of WordArt
shape.FillColor = System.Drawing.Color.Cyan;
shape.StrokeColor = System.Drawing.Color.DarkBlue;
//Save the document
doc.SaveToFile("CreateWordArt.docx", FileFormat.Docx2013);
}
}
}
【VB.NET】
Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Namespace CreatWordArt
Class Program
Private Shared Sub Main(ByVal args As String())
'Create a Document instance
Dim doc As Document = New Document()
'Add a section
Dim section As Section = doc.AddSection()
'Add a paragraph
Dim paragraph As Paragraph = section.AddParagraph()
'Append a shape to the paragraph and specify the shape size and type
Dim shape As ShapeObject = paragraph.AppendShape(400, 150, ShapeType.TextDeflateBottom)
'Set the position of the shape
shape.VerticalPosition = 60
shape.HorizontalPosition = 60
'Set the text of WordArt
shape.WordArt.Text = "Create WordArt in Word"
'Set the fill color and stroke color of WordArt
shape.FillColor = System.Drawing.Color.Cyan
shape.StrokeColor = System.Drawing.Color.DarkBlue
'Save the document
doc.SaveToFile("CreateWordArt.docx", FileFormat.Docx2013)
End Sub
End Class
End Namespace
  
 
							
以上便是如何使用 C# 在 Word 中替換圖像,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群(767755948)

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線