Free Support Forum - aspose.com

List Items with Aspose.Word

I need to create an invoice type of document. I created a template document with mailmerge tags for the current date, invoice number, bill to address info, etc… This is the easy part. Near the bottom of the template I need to list the products and prices in a list type of format

EXAMPLE

Description Amount
=============================== =============
Item 1 10.00
Item 2 15.98
Item 3 250.00

I need advice on the best way to create this type layout on a Word Document. Some code on how to move the cursor would be helpful (or some other method like Aspose.Excel SmartTags). Attached is the template I’m working with.

-Randy

Hi Randy,

Of course, the most applicable way in this case is use of mail merge with regions. I've attached your template as it should look like being prepared for mail merge execution. Here is a sample method performing it:


private void DoMerge(Document doc)

{

// Create a sample data table

DataTable table = new DataTable("Products");


// Add columns

table.Columns.Add("Description", typeof(string));

table.Columns.Add("Amount", typeof(int));


// Add rows

table.Rows.Add(new object[] { "Item1", 10.00 });

table.Rows.Add(new object[] { "Item2", 15.98 });

table.Rows.Add(new object[] { "Item3", 250.00 });


// Execute mail merge with regions

doc.MailMerge.ExecuteWithRegions(table);

}


For additional information please see description of the MailMerge class. Also, take a look how the Sales Invoice demo works, it should be helpful.

Thanks, I was unaware of the ExecuteWithRegions() method. Is the TableStart/TableEnd merge tags suppose to add more rows to the table (see attachment)? I would like to have a fixed size table like in the first attachment and list the Fees/Amounts.

-Randy

TableStart/TableEnd serve as special markers for the repeatable region that allows growing the table dynamically according to the data source. Size of the table (height) depends on row count of the data source. Is there something that doesn't satisfy you? Did I understand you correctly that the current layout (as in the last attachment) is not applicable because the table height isn't fixed (depends on the number of rows)?

The way it works now will do, but I was hoping for the table to expand rather then generate new a new row for each item in the datasource (see attachment).

-Randy

Probably try to put another table without borders into the existing one and place merge region there. If it doesn’t seem applicable, then you should place all the necessary merge fields into the existing table and fill them explicitly using DocumentBuilder.MoveToMergeField instead of mail merge execution although this is a less convenient solution.