翻譯|使用教程|編輯:李顯亮|2021-07-02 11:17:34.777|閱讀 508 次
概述:專業(yè)的 PowerPoint組件,開發(fā)者可以在 .NET 平臺上對 PPT文檔進行生成、修改、轉(zhuǎn)換和打印等操作,而無需安裝 Microsoft PowerPoint。本文介紹如何使用Spire.Presentation for .NET設(shè)置形狀中文字的對齊方式。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Spire.Presentation for .NET 是專業(yè)的 PowerPoint組件,開發(fā)者可以在 .NET 平臺上對 PPT文檔進行生成、修改、轉(zhuǎn)換和打印等操作,而無需安裝 Microsoft PowerPoint。
本文介紹如何使用Spire.Presentation for .NET設(shè)置形狀中文字的對齊方式。可點擊此處下載最新版測試。
設(shè)置 PPT 文字的對齊方式
C#
using Spire.Presentation; using System.Drawing; using Spire.Presentation.Drawing; namespace TextAlignment { class Program { static void Main(string[] args) { //創(chuàng)建Presentation對象 Presentation presentation = new Presentation(); presentation.SlideSize.Type = SlideSizeType.Screen16x9; //添加形狀 IAutoShape textShape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 50, 400, 200)); textShape.ShapeStyle.LineColor.Color = Color.DarkGray; textShape.Fill.FillType = FillFormatType.None; //刪除默認段落 textShape.TextFrame.Paragraphs.Clear(); //添加段落和文字 textShape.TextFrame.Paragraphs.Append(new TextParagraph()); textShape.TextFrame.Paragraphs[0].TextRanges.Append(new TextRange("文字對齊方式")); textShape.TextFrame.Paragraphs[0].TextRanges[0].FontHeight = 20f; textShape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("黑體"); textShape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid; textShape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black; //設(shè)置文字水平靠右 textShape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right; //設(shè)置文字垂直靠下 textShape.TextFrame.AnchoringType = TextAnchorType.Bottom; //保存文檔 presentation.SaveToFile("AlignText.pptx", FileFormat.Pptx2013); } } }
VB.NET
Imports Spire.Presentation Imports System.Drawing Imports Spire.Presentation.Drawing Namespace TextAlignment Class Program Shared Sub Main(ByVal args() As String) '創(chuàng)建Presentation對象 Dim presentation As Presentation = New Presentation() presentation.SlideSize.Type = SlideSizeType.Screen16x9 '添加形狀 Dim textShape As IAutoShape = presentation.Slides(0).Shapes.AppendShape(ShapeType.Rectangle,New RectangleF(50,50,400,200)) textShape.ShapeStyle.LineColor.Color = Color.DarkGray textShape.Fill.FillType = FillFormatType.None '刪除默認段落 textShape.TextFrame.Paragraphs.Clear() '添加段落和文字 textShape.TextFrame.Paragraphs.Append(New TextParagraph()) textShape.TextFrame.Paragraphs(0).TextRanges.Append(New TextRange("文字對齊方式")) textShape.TextFrame.Paragraphs(0).TextRanges(0).FontHeight = 20f textShape.TextFrame.Paragraphs(0).TextRanges(0).LatinFont = New TextFont("黑體") textShape.TextFrame.Paragraphs(0).TextRanges(0).Fill.FillType = FillFormatType.Solid textShape.TextFrame.Paragraphs(0).TextRanges(0).Fill.SolidColor.Color = Color.Black '設(shè)置文字水平靠右 textShape.TextFrame.Paragraphs(0).Alignment = TextAlignmentType.Right '設(shè)置文字垂直靠下 textShape.TextFrame.AnchoringType = TextAnchorType.Bottom '保存文檔 presentation.SaveToFile("AlignText.pptx", FileFormat.Pptx2013) End Sub End Class End Namespace
效果圖:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn