Formatting Problem


#1

Hi Aspose-Team,

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.

Why is there a problem? Can you help me?


#2

Please provide a code snippet sufficient to reproduce the problem.


#3

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!


#4

Please clarify:

Are you loading and saving with Aspose.Word or with MS Word?


#5

I only use your load and save method…


#6

i_WordDocument = new Aspose.Word.Document( l_WordTemplateFilename );
i_WordDocument.Save( l_DocFileName );


#7

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?

John


#8

No, it is not.

The style for “Gesamt MwSt.” for example is “Standard + Trebuchet MS, 11 pt, Fett” (Standard + Trebuchet MS, 11 pt, bold)

After save function, this style has changed to “Standard + Trebuchet MS, 11 pt”.

Thanks in advance.


#9

Ok, give me 1-2 days for research. I will try to find out what the problem is and maybe come up with some workaround.


#10

Have you found a solution for the problem?


#11

Sorry, not yet. Our schedule is very tight. Please give me a couple of days more. I will post the results here.


#12

Any update on this issue please? I seem to have hit the same problem.

Aspose.Words 3.5.0.0 eval running against .NET 2.0 using C# 2005.

The code couldn’t be simpler:

Document doc = new Document(args[0]);
doc.Save(args[0]+".out.doc");

On some test documents, whole paragraphs have been emboldened.

I’m currently trying to repro’ the above on a non-confidential document, which I can then forward to you.

TIA

Pete


#13

This issue is added to our bug list. We plan to deal with it on the next week.

Thank you for your patience.


#14

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.


#15

Ok, when I do this workaround it’s alright.

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?


Thank you very much.



#16

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:

builder.MoveTo(formField.NextSibling.NextSibling);

builder.Writeln("some text");

But it won't help you to preserve form field formatting.


#17

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:

  1. FieldStart - start
  2. BookmarkStart
  3. Run - field code such as " FORMTEXT "
  4. FormField - contains ffdata
  5. FieldSeparator - separator
  6. Run - could be several, contain field value
  7. FieldEnd - field end
  8. BookmarkEnd

I've also seen this layout in some cases:

  1. BookmarkStart
  2. FieldStart - start
  3. Run - field code, one or more runs
  4. FormField
  5. FieldSeparator - separator
  6. Run - field value, one or more runs
  7. FieldEnd - field end
  8. 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.


#18

Check http://www.aspose.com/Community/Forums/41764/ShowPost.aspx for a good example how to set FormField font properties. It is non-trivial task with the current API but it is in our plans to improve it.

I have logged it to our defect base as Issue #830.


#19

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.

What can I do?


#20

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:

string filename = Application.StartupPath + @"\doc7.doc";

Document doc = new Document(filename);

FormField ff = doc.Range.FormFields["Text1"];

ff.SetTextInputValue("Some other FormField text");

doc.Save(Application.StartupPath + @"\doc7_modified.doc");

I have attached the template file I have used.