PPT控件Spire.Presentation 教程:在幻燈片表格中爲文本設置水平對齊

本文將重點介紹瞭如何設置C#中演示幻燈片表格上文本的水平對齊方式。 對於Spire.Presentation的文本對齊方式有五個選項:左,右,中心,對齊和無。html

首先,檢查默認的對齊文檔(左)。 而後,將對錶上的不一樣行應用不一樣的對齊樣式。ide

Step 1:建立演示文稿並從文件加載示例文檔。orm

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

Step 2:從示例文檔獲取表。htm

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

Step 3:水平對齊文字。blog

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

完整代碼:get

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);
    }

慧都控件網string

相關文章
相關標籤/搜索