We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ParagraphFormat.Style returns incorrect font values using C#

Hello! I found a bug when reading the font for first paragraph in last section. I open it and can see it is Comic Sans MS, but in code, it is read as Times New Roman, although Times New Roman is nowhere used in the document.
I attach a test project.

Regards!

Hi Dragos,

Thanks for your query. I have tested the scenario and have managed to reproduce the same problem at my end. I have logged this issue in our issue tracking system and you will be notified via this
forum thread once this issue is resolved.

Please use the following code snippet for a workaround.

<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>AR-SA</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:DontVertAlignCellWithSp/>
<w:DontBreakConstrainedForcedTables/>
<w:DontVertAlignInTxbx/>
<w:Word11KerningPairs/>
<w:CachedColBalance/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-qformat:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Times New Roman"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}

<![endif]–>

var doc = new Document(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "test.docx"));

Console.WriteLine("Test first paragraph in last section font");

Console.WriteLine("Expected Font: Comic Sans MS");

//Console.WriteLine("Actual Font: " + doc.LastSection.Body.Paragraphs[1].ParagraphFormat.Style.Font.Name);

Console.WriteLine("Actual Font: " + doc.LastSection.Body.Paragraphs[1].Runs[0].Font.Name);


Hi

Thanks for your inquiry. I closed the issue as “Not a Bug”. Actually, formatting of text in MS Word documents can be defined on few different levels:

1. Paragraph style defined for the particular paragraph;

2. Character style defined for the particular run;

3. Explicit formatting specified for a particular run.

For more information, please see the following link:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/object-model-overview.html

So you cannot determine whether paragraph has for example bold text by checking just paragraph’s style. There can be a run with bold text.

Hope this helps. Please let me know if you need more assistance, I will be glad to help you.

Best regards,