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

Free Support Forum - aspose.com

How to know attributes have not been set?


Using your api almost all of your methods return default values in case an attribute has not been set.
For example : run.getFont().getName() return default font name even i never set its font name.

Is there a way to know if an attribute has been set or not ?

This is a problem because when we are loading a document using Aspose, we are unable to know if a Run as font name overriden to the default font name (so in this case it means changing the paragraph font name won’t change the run font name) or not.

Hi Jean-Pascal,

Thanks for your inquiry. All the properties of each node is set after loading the document into Aspose.Words DOM. Please note that all text of the document is stored in runs of text. When you load a document into Aspose.Words DOM, Run.Font’s properties are set accordingly.

You can check the Font.Name property either it is default font (Times New Roman) or not. Hope this answers your query. Please let us know if you have any more queries.

Hi Tahir,

I’m afraid but that does not answers my query.

I have a word file with a paragraph linked to a style named “Style1” and with font : Arial, 14pt.
This paragraph contains some text with no font properties set. So Word will displayed the text with Font Arial, 14pt because the paragraph is linked to the style "Style1"
If i change the font of the style “Style1” to Garamond, 10pt, Word will displayed the text of the paragraph with this new Font.

Now using your API to load the document, when i call run.getFont(), it returns the font used in the style “Style1”. Which is not exactly true. In fact the font of the run is not set.

So i cannot rebuild the exactly same Word document. As you always return a value for the font properties of the run, i always set the font properties of the run in the new document. Doing this way, in the rebuilt Word document, the run Font is displayed correctly but if i change the font of the style “Style1” Word won’t change the font of the run. Because i overriden it.

Hope this is a bit more clar.

We need to know if an attribute as been set or not in order to know if we have to use the set method or not when we are rebuilding the document.

Hi Jean-Pascal,

Thanks for sharing the detail. There is no specific way to determine either the value of a property is set or not.

Please note that formatting is
applied on a few different levels. For example, let’s consider
formatting of simple text. Text in documents is represented by Run
element and a Run can only be a child of a Paragraph. You can apply
1) to Run nodes by using Character Styles e.g. a Glyph Style
2) to the parent of those Run nodes i.e. a Paragraph node (possibly via paragraph Styles)
you can also apply direct formatting to Run nodes by using Run
attributes (Font). E.g if you apply Garamond, 10pt to some text, you can use Run.Font.

The problem is we don’t want to apply formatting.

Here is what we are trying to do :

1/ Loading the document with Aspose.
2/ Building our own model while parsing the Aspose model of the loaded document
3/ Building a new Aspose model while parsing our own generated model
4/ Generating word file from the new Aspose model.

So we really need to know if we have to set font formatting properties on each element or not.
Otherwise we’ll never get the same final Word document.

Is there any workaround to try to do this ? If not do you plan to add such feature in a futur release ?

Hi Jean-Pascal,

Thanks for your inquiry.

Aspose.Words does not provide any API to check either the value of a property is set or not.

If you load a Word document into Aspose.Words DOM, all the font formatting is set according to the font formatting of input Word document.