C# Powerpoint中形状的部分下划线检查不起作用?
上面的代码检查powerpoint形状是否。。。 1.所有文本都加了下划线 2.所有文本均未加下划线 3.部分文本加下划线 第三点,带下划线的部分文本无效,对于形状中的混合下划线文本,随机返回false或true 对于粗体和斜体,也就是C# Powerpoint中形状的部分下划线检查不起作用?,c#,powerpoint,partial,shapes,underline,C#,Powerpoint,Partial,Shapes,Underline,上面的代码检查powerpoint形状是否。。。 1.所有文本都加了下划线 2.所有文本均未加下划线 3.部分文本加下划线 第三点,带下划线的部分文本无效,对于形状中的混合下划线文本,随机返回false或true 对于粗体和斜体,也就是 ppShape.TextFrame.TextRange.Font.Underline == MsoTriState.msoTrue ppShape.TextFrame.TextRange.Font.Underline == MsoTriState.msoFals
ppShape.TextFrame.TextRange.Font.Underline == MsoTriState.msoTrue
ppShape.TextFrame.TextRange.Font.Underline == MsoTriState.msoFalse
ppShape.TextFrame.TextRange.Font.Underline == MsoTriState.msoTriStateMixed
我也在GitHub向微软提出了这个问题,
请告诉我是否有任何方法可以解决此问题,或者至少有其他解决此问题的方法???作为解决方法,您可以检查TextRange中的每次运行。在VBA中,可以将形状传递给如下函数:
ppShape.TextFrame.TextRange.Font.Bold == MsoTriState.msoTriStateMixed
ppShape.TextFrame.TextRange.Font.Italic == MsoTriState.msoTriStateMixed
如果文本中的任何字符带有下划线,该函数将返回True。感谢您对TextRange.Runs方法的介绍,这确实是一个很棒的函数,它还可以节省大量性能,而不是循环字符 我在C#.Net中创建了一个类似的函数,以方便地使用与默认函数类似的函数
Function IsUnderlined(oSh As Shape) As Boolean
Dim oRng As TextRange
For Each oRng In oSh.TextFrame.TextRange.Runs
If oRng.Font.Underline Then
IsUnderlined = True
Exit Function
End If
Next
End Function
更新1:微软取得了发展的成功。
using pp = Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;
public static MsoTriState IsUnderlined(pp.Shape parShape)
{
int cntUnderline = 0;
foreach (pp.TextRange textTR in parShape.TextFrame.TextRange.Runs())
{
if (textTR.Font.Underline == MsoTriState.msoTrue)
{
cntUnderline++;
}
}
if (cntUnderline == 0)
{
//No Underline
return MsoTriState.msoFalse;
}
else if (parShape.TextFrame.TextRange.Runs().Count == cntUnderline)
{
//All Underline
return MsoTriState.msoTrue;
}
else if (parShape.TextFrame.TextRange.Runs().Count != cntUnderline)
{
//Mixed Underline
return MsoTriState.msoTriStateMixed;
}
return MsoTriState.msoTriStateToggle; //Consider as error
}