.NET OpenXML SDK 2 RunProperties - Null

I am trying to read a Word 2007 docx document.

The document looks good inside Word, but when I try to read the identifier using my code, all Run objects have RunProperites that set to zero.

The property that interests me the most is RunProperies.FontSize, but unfortunately it is null, the only property I can access is InnerText.

My code is as follows:

using (WordprocessingDocument doc = WordprocessingDocument.Open(filename, true))
{
    MainDocumentPart mainPart = doc.MainDocumentPart;
    IList<Paragraph> paragraphList = doc.MainDocumentPart.Document.Body.Elements<Paragraph>().ToList<Paragraph>();

    foreach (Paragraph pr in paragraphList)
    {   
        IList<Run> runList = pr.Elements<Run>().ToList<Run>();
        foreach (Run r in runList)
        {
            // Some logic
        }
    }
}

I minimized my document as simple as possible and it looks like http://dl.dropbox.com/u/204110/test.docx

I have a similar document that reads well. Is it possible that there is an error in the OpenXML SDK 2?

Has anyone had similar problems? Any help would be appreciated. Thank!

+3
1

FontSize RunProperties. , r.RunProperties , , r.RunProperties.FontSize null, . - :

uint fontSize = SOME_DEFAULT_FONT_SIZE;
RunProperties propertiesElement = r.RunProperties;
if (propertiesElement != null) {
  FontSize sizeElement = propertiesElement.FontSize;
    if (sizeElement != null) {
      fontSize = sizeElement.Val.Value;
    }
  }
}

docx, DocReflector, SDK, , 3 , 4- .

+2

Source: https://habr.com/ru/post/1730383/


All Articles