我必须将智能艺术转换为文本视图,与“转换为文本”功能区的工作高亮显示在第1张图像下方。直到现在我能够从智能艺术中提取文本并将其写入形状。但我发现了以下问题。
删除智能艺术形状后,它会在幻灯片中添加空白形状。
以下是我所拥有的代码
private void ChangeSmartartToText(ref PresentationEXT textDeck, string deckType)
{
PPT.Slide slide = textDeck.destinationPresentation.Slides[textDeck.currentSlideNumber+1];
PPT.Shape tempSmartShape = null;
foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in slide.Shapes)
{
if (shape.HasSmartArt == MsoTriState.msoTrue)
{
tempSmartShape = shape;
break;
}
}
PPT.Shape newTextShape = null;
if (tempSmartShape != null)
{
var smartartTop = tempSmartShape.Top;
var smartartLeft = tempSmartShape.Left;
var smartartHeight = tempSmartShape.Height;
var smartartWidth = tempSmartShape.Width;
newTextShape = slide.Shapes.AddShape(MsoAutoShapeType.msoShapeRectangle, smartartLeft, smartartTop, smartartWidth, smartartHeight);
var val1 = tempSmartShape.SmartArt;
string name = val1.Layout.Name;
string category = val1.Layout.Category;
StringBuilder smartartText = new StringBuilder();
foreach (SmartArtNode node in val1.AllNodes)
{
smartartText.AppendLine(node.TextFrame2.TextRange.Text);
}
Microsoft.Office.Interop.PowerPoint.TextRange objText;
objText = newTextShape.TextFrame.TextRange;
newTextShape.TextFrame.Orientation = MsoTextOrientation.msoTextOrientationHorizontal;
objText.Text = smartartText.ToString();
tempSmartShape.Delete();
tempSmartShape = null;
}
}
答案 0 :(得分:1)
这里有一点你可以开始的VBA。在每个If / Then包含一个应用程序定义的常量(msoThis或ppThat)之后,我添加了一个注释,其中包含常量的实际值(VBAspeak中的Longs,可能是.Net中的Integers)
Sub Thing()
Dim oSl As Slide
Dim oSh As Shape
For Each oSl In ActivePresentation.Slides
For Each oSh In oSl.Shapes
If oSh.Type = msoSmartArt Then ' 24
MsgBox "SMARTART!"
End If
If oSh.Type = msoPlaceholder Then ' 14
If oSh.PlaceholderFormat.Type = ppPlaceholderObject Then ' 7
If oSh.PlaceholderFormat.ContainedType = msoSmartArt Then
MsgBox "SMARTART!"
End If
End If
End If
Next
Next
End Sub
答案 1 :(得分:0)
这是另一个VBA代码段,演示了如何通过对象模型设置缩进级别;它的工作范围是1到9(但在旧版本的PPT中,只支持5个级别)。
Dim oSh As Shape
Dim x As Long
Dim lIndent As Long
Set oSh = ActiveWindow.Selection.ShapeRange(1)
With oSh.TextFrame2.TextRange
For x = 1 To .Paragraphs.Count
.Paragraphs(x).ParagraphFormat.IndentLevel = x
Next
End With