We are generating invoices.
There is a “for each” loop in the body of the word document with a page break, meaning each invoice should start in a new page. However, a single invoice may have too many line items and span through multiple pages.
The idea is to have the invoice number in the page footer as well.
The attached template will give will an idea of what I’m trying to accomplish, I’m wondering if this is even possible.
Please check these template/output Word documents (Invoices_Template.zip (23.5 KB)) and try running the following code:
List<List<string>> invoices = new List<List<string>>();
for (int i = 0; i < 3; i++)
{
invoices.Add(new List<string>());
for (int j = 0; j < 50; j++)
invoices[invoices.Count - 1].Add("Item " + (j + 1));
}
Document doc = new Document("E:\\temp\\Invoices.docx");
ReportingEngine engine = new ReportingEngine();
engine.Options |= ReportBuildOptions.RemoveEmptyParagraphs;
engine.BuildReport(doc, invoices, "invoices");
doc.UpdateFields();
doc.Save("E:\\temp\\19.11.docx");
I think, this is the simplest way to meet your requirement. In this case, updating of fields is required. And also note how fields are used in the template. Hope, this helps.
Thanks. I see a field in the footer what I cannot understand is is connected to the data. Would you mind explaining?
When I open the word the field reads: “Error, reference source not found.”
If I right click on it, “Edit Field” is not available. If I click on “Toggle Field Codes” then I see:
Yes, you are right. But, after when ReportingEngine.BuildReport executes then calling the Document.UpdateFields method will dynamically calculate the correct value of REF field in footer.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.