I attached two Word-Documents in a zip-File. The “InvoiceTemplate.dot” is the input Word-Document. After filling the form fields with values and saving it I get the file “InvoiceResult.doc”.
If you look special to the last part of this document you will see, that the format is different to the input document (InvoiceTemplate.dot). Some words and lines have been formatted as bold and so on.
I just have done an experiment: I load the .dot-File and after that I directly save it again (without filling or rather do anything with the content of the document). The result with the different formatting is the same!
It sounds to me that the template file has a defined style that you are using but isn’t actually stored in the .dot template file. The style is probably saved the normal.dot file. Before I go any further, here is my question…
If you open the .dot file in MS Word, is the text that is changing style formatted with/by a user defined style?
When using latest Aspose.Words 3.5 the only formatting that is lost is Bold from the header cells in the tables in the document.
I’ve traced this down to the table style. Your tables use the Table Grid style and that style has Bold for font in the headers specified.
Aspose.Words does not fully support table and list styles and hence the problem. Full support for table and list styles is on our task list, but it is not a quick fix. You can workaround by using only character styles, paragraph styles and direct formatting, but don’t use table styles.
I found some more problems and I hope you can tell what I have to do.
In my word documents I have formatted some form fields - for example bold+italic and saved it from Word2003 as a doc-file. After filling it with a value with your method .SetTextInputValue(…) the format bold+italic has gone and the form field only has the standard-format (no bold, no italic).
Another problem is the following. Maybe it is my fault.
I have a form field in my word document. I only want to use this form field to move with my documentbuilder to it, in order to write at the this position some text:
if (l_FormField.Name.Equals("TAX_KEYS") )
{
i_WordDocumentBuilder.MoveTo( l_FormField );
i_WordDocumentBuilder.Write("T-e-s-t");
}
but it does not what i described above. There is no text “T-e-s-t” at the position (nowhere at all) where the form field TAX_KEYS is. Can you help me with that problem too?
Unfortunately, in our current object model form field formatting cannot be controlled or preserved. I have logged this issue to our defect base (issue 821). We are planning to deal with it in the next 2-3 weeks.
If you want to insert text to form field using DocumentBuilder you need to use the following construct:
I just wanted to add more info why moving to a form field and inserting text using document buildes does not work and why you have to use strange looking FormField.NextSibling.NextSibling to do that.
The reason is that a complete form field in a Word document is a complex structure represented by several nodes: field start, field code such as FORMTEXT, form field data, field separator, field result, field end and a bookmark.
In a document tree the nodes are arranged like this:
FieldStart - start
BookmarkStart
Run - field code such as " FORMTEXT "
FormField - contains ffdata
FieldSeparator - separator
Run - could be several, contain field value
FieldEnd - field end
BookmarkEnd
I’ve also seen this layout in some cases:
BookmarkStart
FieldStart - start
Run - field code, one or more runs
FormField
FieldSeparator - separator
Run - field value, one or more runs
FieldEnd - field end
BookmarkEnd
Using DocumentBuilder.MoveTo(FormField) moves the cursor to be before the FormField node. Then you use DocumentBuilder.Writeln(text) and that inserts text before the FormField node.
Therefore, the text is inserted into the field code. This is not a correct thing to do, you should not really have your text in the field code. Your text should be in the field result, that is between the FieldSeparator and FieldEnd nodes. Using FormField.NextSibling yelds the FieldSeparator node and using another NextSibling yelds the first node after the field separator. It is the correct place to insert text for you.
If this sounds complex, you should be using just FormField.Result = “MyText”. This method does just what I’ve described above.
I don’t want to set FormField font properties. I wanted to explain, that the FormField font, which was set in MS Word 2003 to bold+italic, afterwards (after using FormField.Result= or FormField.SetTextInputValue(…) ) looses these both properties.
The FormField has standard-format (no bold+italic). But… the font family doesn’t change.
That depends on how you set bold+italic on FormField in MS Word. Try to set formatting on entire FormField including bookmark and spaces around it. That way the formatting will probably stay. At least it stays in my test: