首页 > 解决方案 > power point interop API - TextRange 中的多段无法正常工作

问题描述

我正在尝试使用互操作 API 生成 pptx 文件,但我需要在一个 TextRange(形状)中组合两个段落,但是我找不到任何关于如何在一个 TextRange 中获取两个段落的具体文档,我的代码如下

       //Add title
            Shape sh = slide.Shapes.AddShape(MsoAutoShapeType.msoShapeRectangle,0,0,cm(33.87f),cm(6.4f));

            sh.Fill.Transparency = 1;
            sh.Line.Transparency = 1;
            sh.TextFrame.VerticalAnchor = MsoVerticalAnchor.msoAnchorTop;

            //TextRange objText;
            objText = sh.TextFrame.TextRange;           
            objText.Font.Name = "Microsoft JhengHei";
            objText.Font.NameFarEast = "微軟正黑體";
            objText.Font.Size = 48;
            
            objText.Paragraphs(1).Lines(1).Text = "Title test\r\n";
            objText.Paragraphs(1).Lines(2).Font.Color.RGB = Color.Red.ToArgb();
            objText.Paragraphs(2).Lines(1).Text = "Second Paragraph";
            objText.Paragraphs(2).Lines(1).Font.Color.RGB = Color.Chocolate.ToArgb();

但是我只能得到两行而不是两段的结果

  1. 办公室
  2. 2019 视觉工作室 2019
  3. .NET4.7
  4. 赢表格

标签: c#office-interoppowerpoint-interop

解决方案


推荐阅读