How to get all the fonts used in a document using interop c#?

时间:2016-10-20 13:12:02

标签: c# fonts ms-word interop

I need to make an application which list all the fonts used in a document.

by using this code var val = document.Content.Font.Name; I am able to find the font name only if only one font is used through out the document. if multiple fonts were used the the value of val becomes blank.

Here I uploaded a sample file, in the document I used 3 type of font (Algerian,castellar, and Calibri). I need to find all three. I checked with Openxml there is showing the font name and I think i can get that but I have to use Interop only

XML from OpenXml

<w:r w:rsidRPr="004E2690">
    <w:rPr>
        <w:rFonts w:ascii="Algerian" w:hAnsi="Algerian" />
    </w:rPr>
    <w:t>Madan mohan Mishra</w:t>
</w:r>

1 个答案:

答案 0 :(得分:1)

查找所有使用的字体可能相当复杂,因为Word文档中有很多位置应用了字体对象(从Word中打开VBA,按F2键进入对象浏览器并搜索字体以查看其中的对象Office对象模型带有Font属性)

这篇文章对你有帮助,他们已经完成了整个练习: http://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-mso_other/list-fonts-used-in-a-particular-document/1f673f38-aa1d-4c4c-9e32-a2aec1bfbb96