PPT控件Spire.Presentation 教程:在幻灯片表格中为文本设置水平对齐

本文将重点介绍了如何设置C#中演示幻灯片表格上文本的水平对齐方式。 对于Spire.Presentation的文本对齐方式有五个选项:左,右,中心,对齐和无。

首先,检查默认的对齐文档(左)。 然后,将对表上的不同行应用不同的对齐样式。

Step 1:创建演示文稿并从文件加载示例文档。

Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx",FileFormat.Pptx2010);

Step 2:从示例文档获取表。

ITable table = null;
foreach (IShape shape in presentation.Slides[0].Shapes)
{
    if (shape is ITable)
    {
        table = (ITable)shape;

Step 3:水平对齐文字。

for (int i = 0; i < table.ColumnsList.Count; i++)
{
    table[i, 0].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;
    table[i, 1].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Center;
    table[i, 2].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
    table[i, 3].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.None;
    table[i, 4].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;
}

Step 4:将文档保存到文件。

presentation.SaveToFile("tableresult.pptx", FileFormat.Pptx2010);

效果截图:

图片1

完整代码:

static void Main(string[] args)
{
        Presentation presentation = new Presentation();
        presentation.LoadFromFile("Sample.pptx",FileFormat.Pptx2010);
        ITable table = null;
        foreach (IShape shape in presentation.Slides[0].Shapes)
        {
            if (shape is ITable)
            {
                table = (ITable)shape;
                for (int i = 0; i < table.ColumnsList.Count; i++)
                {
                    table[i, 0].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Right;
                    table[i, 1].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Center;
                    table[i, 2].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Left;
                    table[i, 3].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.None;
                    table[i, 4].TextFrame.Paragraphs[0].Alignment = TextAlignmentType.Justify;
                }
            }
        }
        presentation.SaveToFile("tableresult.pptx", FileFormat.Pptx2010);
    }

慧都控件网

转载于:https://my.oschina.net/u/3006003/blog/1498900

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值