We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

.docx generation and line breaks

Hi everyone,

I am using DocIO to generate word documents.
The process is the following :
- the user selects a word model (.doc or .docx)
- the program detects some specific strings and replace them by data stored in a database (method Replace of WordDocument class)
- the new document is saved (method Save of wordDocument class)

The process is working perfectly when the program generates a .doc, but when a .docx is generated, there is a problem with line breaks.
Indeed, the file is generated, but i can't open it : i get an error "invalid xml character".

I am using the string "\v" to insert line breaks in documents.
If i replace it by "", "\r", or "\r", i get a openable document, but these strings are not line breaks, so it's not an acceptable solution for me.

So my question is simple : what string do i have to use to insert a line break in a .docx ? I'm sorry if my question seems very basic, but i don't understand why "\v" is causing problems in .docx, and not in .doc...

Thanks in advance for your help.

Alexandre.

3 Replies

RA Rajendran Syncfusion Team May 26, 2010 10:55 AM UTC

Hi Alexandre,

Thank you for using Syncfusion products.

For inserting line break in word document please refer the following code snippet:
Code Snippet:
IWParagraph paragraph = section.AddParagraph();
paragraph.AppendBreak(BreakType.LineBreak);

Similarly you can insert column break and page break.
paragraph.AppendBreak(BreakType.ColumnBreak);
paragraph.AppendBreak(BreakType.PageBreak);

Please try this and let us know if you have any other questions.

Regards
Rajendran


AG Alexandre Gex May 27, 2010 12:34 PM UTC

Hi Rajendran, and thanks for your response.

I saw the code you mention in the Syncfusion documentation.
However, I think i cannot use that because i'm just using the method Replace of WordDocument class.

Typically, in my code, I have something like :

WordDocument doc = new WordDocument("inputDoc", FormatType.Docx);
doc.Replace(new Regex("something", RegexOptions.IgnoreCase), "strReplacement");
doc.Save("outputDoc", FormatType.Docx);

The only thing i'd like to do is to insert a line break in "strReplacement". "str\vReplacement" is working in .doc, but not in .docx...

I hope i've exposed my problem more precisely.

Regards,
Alexandre


RA Rajendran Syncfusion Team May 28, 2010 04:48 AM UTC

Hi Alexandre,

Thank you for your update.

We have forwarded this issue to our development team for further analysis.

Could you please report this issue through Direct Trac Developer Support System
https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents because you can take
the advantage of the expertise of a dedicated support engineer and a guaranteed response time and
we hope you will take advantage of this system as well. If you have already reported, please ignore this.

Please let us know if you have any other questions.

Regards
Rajendran

Loader.
Live Chat Icon For mobile
Up arrow icon