翻譯|使用教程|編輯:李顯亮|2021-07-02 11:17:34.777|閱讀 525 次
概述:專業的 PowerPoint組件,開發者可以在 .NET 平臺上對 PPT文檔進行生成、修改、轉換和打印等操作,而無需安裝 Microsoft PowerPoint。本文介紹如何使用Spire.Presentation for .NET設置形狀中文字的對齊方式。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Spire.Presentation for .NET 是專業的 PowerPoint組件,開發者可以在 .NET 平臺上對 PPT文檔進行生成、修改、轉換和打印等操作,而無需安裝 Microsoft PowerPoint。
本文介紹如何使用Spire.Presentation for .NET設置形狀中文字的對齊方式。可點擊此處下載最新版測試。
設置 PPT 文字的對齊方式
C#
using Spire.Presentation;
using System.Drawing;
using Spire.Presentation.Drawing;
namespace TextAlignment
{
class Program
{
static void Main(string[] args)
{
//創建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;
//設置文字水平靠右
textShape.TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;
//設置文字垂直靠下
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)
'創建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
'設置文字水平靠右
textShape.TextFrame.Paragraphs(0).Alignment = TextAlignmentType.Right
'設置文字垂直靠下
textShape.TextFrame.AnchoringType = TextAnchorType.Bottom
'保存文檔
presentation.SaveToFile("AlignText.pptx", FileFormat.Pptx2013)
End Sub
End Class
End Namespace
效果圖:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn