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

Free Support Forum - aspose.com

Carriage return on table end

We just updated to the latest version of Apose.Words. and now we have a client complaining about carriage returns in documents.


She has a document used as a mail merge template, and before we changed versions of Aspose.Words, it would automatically insert 2 carriage returns after the table table end. Now it’s only inserting 1 carriage return.

Is there a way to control this functionality, or will we have to tell our clients that they need to adjust their templates accordingly?

Hi Darren,

Thanks for your request. Could you please attach your template and sample code that will allow to reproduce the problem? We will check the issue and provide you more information.

I think that you can simply disable RemoveEmptyParagraphs option if it is enabled:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.reporting.mailmerge.removeemptyparagraphs.html

Best regards,

Not to be difficult about this, but I do not have access template file directly.

The file is a regular .DOC file with a mail merge table in it. The tag signifying the end of the table is on the same line as the merge content. In the previous version we were using, this resulted in 2 carriage returns. Now it’s only adding 1. We are already using remove empty paragraphs, for the purpose of removing empty paragraphs.

We can tell our customers to manually add the return to their files, but only after we are sure there are no other options. I will try to get a copy of the document.

I have attached a rar file with examples and the source document.


asposess1.png is the new result
asposess2.png is what the old results were
and the last is the mail merge document being used as a template.
We copy the file to a new location and then merge the data into it.

Hi Darren,


Thanks for this additional information.

As Alexey has stated, this issue is most likely occuring because you have set RemoveEmptyParagraphs to true. In the latest versions of Aspose.Words this will also remove the start and end of mail mergions if the paragraph contains no other content.

In your case you should be able to set this setting to false. Please let us know how this goes for you.

Thanks,

I’m not the one who wrote our code for handling this, but I did speak with that developer, and he says we need that property set to true for other reasons. Without any other alternatives, we’re going to have to tell 100+ clients that if they notice formatting errors, then they’ll have to edit the source document.


I do thank you for making this change, we have an area where we’ve had numerous complaints about extra carriage returns. Now those complaints will go away, to be replaced by these new ones.

Hi

Thank you for additional information. You can easily suppress this behavior by inserting a single white space in the paragraphs with TableStart and TableEnd merge fields. I suppose you can do this programmatically.

Best regards,

We can do this programatically, however, it won’t fit with our current logic.


Thank you for your help.

It appears we will have to tell our customers that this is another growing pain.

Hi

Thank you for additional information. Please let us know if you need more assistance, we are always glad to help you.

Best regards,

Hello,

I work for the same company as Darren. This is really a big problem. Is there any way we can avoid having customers change all their documents? We are talking about 10,000 documents overall. We do require RemoveEmptyParagraphs=true, but many customers have built documents expecting that a TableStart_ mergefield will produce a blank line in the document.

By programmatically inserting a single space, do you mean setting our TableStart_ and Tableend_ values to ' ' rather than '' when we produce the data set? If so, we tried that and it didn't seem to make a difference.

Or (after thinking about it more) did you just mean that when the template document has only a TableEnd or TableStart field and a carriage return, programatically add a space to that line?

That works, but we'd either have to do it when we process the files, or provide a utility program that could update users' template files.

Hi there,


Thanks for this additional information.

You could do something dynamically just before mail merge like the code below. This code will make sure that a space exists in the paragraph with TableStart and TableEnd merge fields so they are not automatically removed.

<span style=“font-size:
10.0pt;font-family:“Courier New”;color:blue;mso-no-proof:yes”>foreach<span style=“font-size:10.0pt;font-family:“Courier New”;mso-no-proof:yes”> (Paragraph para in
doc.GetChildNodes(NodeType.Paragraph, true))<o:p></o:p>

{

if (para.Range.Text.Contains("TableStart"))

para.AppendChild(new Run(doc, " "));

else if (para.Range.Text.Contains("TableEnd"))

para.PrependChild(new Run(doc, " "));

}


Please let us know if this is suitable for you.

Thanks,

Instead of doing this in the code, can we just change our queries for the data source to use ' ' instead of ''? This is currently what we are doing for our TableStart_ and TableEnd_ columns:

SELECT TableStart_Aliases = '',

Could we simply do this:

SELECT TableStart_Aliases = ' ',

Hello

Thanks for your request. Yes you can do it. Actually Alexey already mentioned you about this:

You can easily suppress this behavior by inserting a single white space in the paragraphs with TableStart and TableEnd merge fields.”

Best regards,

Actually, we couldn't get this to work, but we were able to add a simple space to the document on the same line as the TableStart tab with only that and a carraige return. It's only ok to add a space on a line where there is no other content anyway or else we could disrupt the layout in other ways.

We resolved to build a utility to process existing templates and where there are lines that consist of just a tablestart or tableend tab and a carraige return, add a space. We will provide this to any customers that request it after they receive the application update.

Thank you for your help with this one; I think we know how to proceed now.

Karen

Hi Karen,


It’s great things are working as expected now, please feel free to ask any time you have any queries. Also note that the code provided above does exactly what you ended up doing, although it did not check if the paragraph range was empty or not.

Thanks,