如何使用Docx dll获取段落FontName? [英] How get paragraph FontName with Docx dll?

查看:91
本文介绍了如何使用Docx dll获取段落FontName?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Docx dll来获取段落信息但不能获得段落格式(font size-fontName-FontColor)这是我的代码:





I am using Docx dll to get paragraph information but not able to get paragraph format(font size-fontName-FontColor) Here is my code for that:


using (DocX document = DocX.Load("Test.docx"))
{

    if (document.Paragraphs.Count() > 0)
    {

        for (int i = 0; i < document.Paragraphs.Count; i++)
        {
            Novacode.Paragraph pg = document.Paragraphs[i];
            Console.WriteLine("Text:" + pg.Text +" Alignment:" + pg.Alignment + " Direction:" + pg.Direction);
            //how get FontName-FontSize
        }
    }
}

推荐答案

如果文本格式化,您可以通过段落中的MagicText属性访问格式

if a text is formatted you can access the formats via the MagicText property in the paragraph
foreach (var mt in pg.MagicText)
{
  if (mt == null)
     continue;
  if (mt.formatting != null)
  {
  FontName = mt.formatting.FontFamily.Name.ToString();
 }
}


这篇关于如何使用Docx dll获取段落FontName?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆