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

Free Support Forum - aspose.com

Words: Multi-section documents and execute template (handlebars)

Hello All,


I’m having trouble with a multi-section Word template (docx), which I have attached.

The structure of the document is simple: A header section, followed by a single-column section, followed by a two-column section. A Preamble field’s text in the single-column section should span the entire page. The addresses, however, should flow into two columns in the next section.

It would seem that Words does not tolerate a root foreach that spans multiple sections, which might explain why I cannot push data into headers and footers.

Two questions, then:

  • Where should I put the root foreach to accommodate this structure?
  • How do I push data into headers and footers?

Thank you!
Hi Eric,

Thanks for your inquiry. Please attach the following resources here for testing:

  • Aspose.Words generated output document which shows incorrect result
  • Your expected document showing the correct result. You can create expected document using Microsoft Word.
  • Please create a standalone Console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing..

As soon as you get these pieces of information ready, we'll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click 'Reply' button that will bring you to the 'reply page' and there at the bottom you can include any attachments with that post by clicking the 'Add/Update' button.

Best regards,

Hi Awais,


Thank you for getting to me.

I’ll have to get back to this tomorrow. The UI on your account management is still now working properly. I can log in, view the dashboard, my files, etc., but I cannot upload files. I’ll need to be able to do that in order to give you the test case and accompanying data.

I’m working with Muhammad through the forum to resolve the issue.

Thanks, again!

Hi Awais,

I changed the test case, but the problem is the same.

I have attached the following (in a ZIP file):

  • proposal.xml (XML generated by the client application)
  • proposal2.docx (template file in Word format)
  • proposal.pdf (output)

The Web API endpoint I’m calling is this (with the XML file as the payload):

http://api.aspose.com/v1.1/words/Proposal2.docx/executeTemplate?withRegions=true&cleanup=UnusedRegions,UnusedFields,RemoveTitleRow

My questions:

  • How do I push data into headers and footers?
  • How do I deal with multi-section Word documents in general, where obviously the outermost foreach will embrace multiple sections?
  • Why is RemoveTitleRow not working?

Thank you!

Hi Eric,


Thanks for the additional information. We are working over your query and will get back to you soon.

Best regards,

Hello,


Where is everybody?

If you guys are going to offer a cloud service, you cannot take the amount of time you’re taking to respond to questions. I asked my question 9 days ago, and I still do not have an answer.

We use the following backend cloud services: Twilio, Mailgun, SmartyStreets, FogBugz (for error reporting), and YouTrack for agile. We also use Litmus for testing our HTML-based emails. All of these services offer the following:

  • For free email support, 2-day response time (but usually we get a response in a few hours)
  • For paid support, anywhere from 1-hour to 8-hour SLA’s

You’re paid support guarantees 24-hour response, and that’s just not acceptable for applications in production. Also, some companies are just starting up and need to take advantage of free support initially.

Offering a forum for support is not the same as offering support. The forum is awesome, to be sure, but it is merely a venue. Imagine if only the community ever answered your customers’ questions. You would never have had to bear the cost of supporting those customers.

I need to get an answer to my question please.

Thank you.

Hi Eric,

Thanks for your inquiry and sorry for the delayed response.

1 - After executing mail merge with regions, please execute simple mail merge to be able to push data into headers and footers.

2 - Please follow these simple rules when marking a region in Word document:

  • TableStart and TableEnd fields must be inside the same section in the document.
  • If used inside a table, TableStart and TableEnd must be inside the same row in the table.
  • Mail merge regions can be nested inside each other.
  • Mail merge regions should be well formed (there is always a pair of matching TableStart and TableEnd with the same table name).

3 - We managed to reproduce this issue on our end and are checking this scenario further. We will keep you informed via this thread. We apologize for your inconvenience.

Best regards,

Hi Awais,


I will work the additional call to simple mail merge this evening. Thank you for that advice. You might want to update your documentation to reflect the need to do that.

As for the the issue, I eagerly await your response.

Thank you!

Hi Awais,


I have had time to look into the simple mail merge call in order to push data into headers. I have a few questions:

  1. Is simple mail merge not supported for the moustache-style tags ({{ }})? Should the headers and footers be defined with actual merge fields instead?
  2. Does executing simple mail merge again go against our monthly “ops” allowance?
  3. What exactly is the workflow? I imagine that we have to use the document generated from the first call (the executeTemplate call) as input into the simple mail merge, after which a PDF is requested (in our case).

Our biggest concern is item #2 above.

Thank you.

Hi Eric,


Thanks for your inquiry. After executing mail merge with regions, there will be an intermediate document stored on cloud storage. Due to mustache fields in headers, you need to again execute ‘simple mail merge’ on the intermediate document. Yes, this will be an extra operation (point#2). Here is sample code:

AsposeApp.AppSID = “”;

AsposeApp.AppKey = "";

string fileName = "Proposal2-Intermediate.docx";

string outFileName = "final-output.docx";

string xml = "<?xml version='1.0' encoding='UTF-8'?>" +

" " +

" ABC Company, Inc.ABC Company, Inc" +

" 2015-00046" +

" ";

string strURI = "http://api.aspose.com/v1.1/words/" + fileName + "/executeTemplate?withRegions=false&filename=" + outFileName;

string signedURI = Utils.Sign(strURI);

Stream responseStream = Utils.ProcessCommand(signedURI, "POST", xml, "XML");

StreamReader reader = new StreamReader(responseStream);

string strJSON = reader.ReadToEnd();


Hope, this helps.

Best regards,

Hi Awais,


Thank you for your response.

Pushing data into headers and footers costs an extra operation? Really? So, you’re are, in essence, collecting additionally money from your customers simply because they wish to push data into headers and footers?

The need for two passes is an inefficiency of your service, not a request artifact. There is no reason why, on the server itself, you can’t pipe the output of the first merge into a second merge for the headers and footers, and then write out the merge document…and I’m only assuming that two passes are truly necessary. As a developer who is intimately familiar with the structure of Word documents, I don’t see any technical reason for two passes, and I would never write my API that way.

Please increase our monthly ops limit by 33% to accommodate the additional, unnecessary call.

Thank you.

Hi Eric,


Thanks for your inquiry.

Text of a Word document is said to consist of several stories. The main text is stored in the main text story represented by Body class and each header and footer is stored in a separate story represented by HeaderFooter class.

The problem occurs because mustache fields in headers are actually not a part of “Proposal region”. The start/end field markers of this region are located inside the Body story but content of headers/footers is located at a different story. That is why Aspose.Words ignores those fields in header.

If you want to get it done in a single call then you have to modify template document. Since, Aspose.Words allows duplicate regions in template, so I have added an extra “Proposal region” and encapsulated existing mustache fields in headers in it (see attached Proposal2-modified.docx).

Hope, this helps.

Best regards,

Hi Awais,


Yes, including additional, identical foreach’s in the headers and footers solved the problem. If you could update your documentation to reflect the need to do that when headers and footers are present, that would be great.

So, then, the only problem left to solve is why the clean-up options are not actually removing empty tables (as you can see from earlier in the thread).

Thank you.

Hi Eric,


Thanks for your inquiry. We will be sure to update documentation accordingly.
Eric:
So, then, the only problem left to solve is why the clean-up options are not actually removing empty tables (as you can see from earlier in the thread).
We have raised this issue with our product team. The ID of this issue is WORDSCLOUD-1. Your thread has been linked to this issue and you will be notified via this thread as soon as it is resolved. Sorry for the inconvenience.

Best regards,

Hi Awais,


O.K. That’s great. I hope you’re able to resolve this problem in the next few weeks, which is when we go live.

Thank you!
Hi Eric,

Thanks for being patient. Please use cleanup option "RemoveTitleRow,RemoveTitleRowInInnerTables" because these tables (on page 2 and 3) are inner for region "Proposal". Hope, this helps.


It is to update you that the issues you have found earlier (filed as WORDSCLOUD-1) have been fixed in
this Aspose.Words for Cloud update.

Best regards,