本文整理汇总了C#中ParagraphProperties.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# ParagraphProperties.Descendants方法的具体用法?C# ParagraphProperties.Descendants怎么用?C# ParagraphProperties.Descendants使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParagraphProperties
的用法示例。
在下文中一共展示了ParagraphProperties.Descendants方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFormatParagraph
/// <summary>
/// Add format paragraph
/// </summary>
/// <param name="paragraphProperties"></param>
/// <returns></returns>
private string AddFormatParagraph(ParagraphProperties paragraphProperties)
{
List<string> cssStyleElements = new List<string>();
string paragraphStyle = "";
if (paragraphProperties != null)
{
ParagraphStyleId paragraphStyleId = paragraphProperties.Descendants<ParagraphStyleId>().FirstOrDefault();
if (paragraphStyleId != null)
paragraphStyle = paragraphStyleId.Val;
}
paragraphStyle = "\"" + paragraphStyle + "\"";
Indentation indentation = paragraphProperties.Indentation;
/*
if (indentation != null)
{
if (indentation.Left != null)
cssStyleElements.Add(string.Format("margin-left:{0}pt", ConvertDxaToPoint(indentation.Left.Value)));
else if (indentation.FirstLine != null)
//cssStyleElements.Add(string.Format("text-indent:{0}pt", ConvertDxaToPoint(indentation.FirstLine.Value)));
cssStyleElements.Add(string.Format("margin-left:{0}pt", ConvertDxaToPoint(indentation.FirstLine.Value)));
}*/
NumberingProperties numberingProperties = paragraphProperties.NumberingProperties;
if (numberingProperties != null && numberingProperties.NumberingLevelReference != null && numberingProperties.NumberingId != null)
{
int level = numberingProperties.NumberingLevelReference.Val.Value;
int numId = numberingProperties.NumberingId.Val.Value;
int abstractNumId = document.MainDocumentPart.NumberingDefinitionsPart.Numbering.Descendants<NumberingInstance>().Where(x => x.NumberID == numId).FirstOrDefault().AbstractNumId.Val.Value;
indentation = document.MainDocumentPart.NumberingDefinitionsPart.Numbering.Descendants<AbstractNum>().Where(x => x.AbstractNumberId == abstractNumId).FirstOrDefault().Descendants<Level>().Where(x => x.LevelIndex.Value == level).FirstOrDefault().Descendants<Indentation>().FirstOrDefault();
Level numberingLevel = document.MainDocumentPart.NumberingDefinitionsPart.Numbering.Descendants<AbstractNum>().Where(x => x.AbstractNumberId == abstractNumId).FirstOrDefault().Descendants<Level>().Where(x => x.LevelIndex.Value == level).FirstOrDefault();
if (numberingLevel.LevelText.Val.Value.Contains("%"))
cssStyleElements.Add(string.Format("mso-list:l{0} level{1} ol", numId, level + 1));
else
cssStyleElements.Add(string.Format("mso-list:l{0} level{1} ul", numId, level + 1));
}
string result = "";
foreach (string element in cssStyleElements)
result += element + ";";
if (result != "")
result = paragraphStyle + string.Format(" style='{0}'", result);
else
result = paragraphStyle;
return result.Trim();
}