How to use aspose.word the achieve complex reports

I want to use aspose.word to generate a report like this;

which with table 1 and 2,in this report:
1、the number of columns in Table 1 is uncertainty,when more than four, then the generate a new page which like Table 1, with the amount of data we generate another page;
2、In Table 2 we hope to repeat the head(this we know how to achieved),at the same time we want some rows’ cells can be merged,

all of the number of rows in the table is not indefinite
through the method MailMerge and template can this be achieved??
here is the table
table 1

No 1 2 3 ……

table 2

Name Unit Num Price Total Remark
1、Test1 400
m 1 10 10
m 2 30 60
m 3 10 30
……. ……. ……. ……. …….
2、Test2 3000
kg 1 20 20
kg 30 30 900
……. ……. ……. ……. …….


Thank you for your interest in Aspose.Words.

  1. I think, for the first case, you can try using the technique as described in the following thread:
  2. For the second situation, in the simplest case (without merged cells), you can use Mail Merge with regions. Please see the following link for more information:

Also, I think information provide in the following forum thread could be useful for you:
Please let me know if you need more assistance or information, I will be glad to help you.
Best regards.

Can you give me some detail code about these table, I am not very familiar with this, thank you!!


Thanks for your request. There is no direct way to build table, which grows horizontally. So implementation of such kind of table will require more coding efforts and will be more tricky. Let’s define few requirements:
a) Table should not grow outside the page margins.
b) If there is more than 5 columns, table span to the “next line”.
c) We will build table from scratch.
d) Bookmark in the template will be used as placeholder.
Once we defined these point, we can build our template. Our template will contain only bookmark at the position where table should be built.
Here is sample code, which will generate such kind of table:

// Open template document.
Document doc = new Document(@"Test001\in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
// Move cursor to bookmark.
// Configure DocumentBuidler.
builder.RowFormat.AllowAutoFit = false;
builder.CellFormat.Borders.LineStyle = LineStyle.Single;
builder.CellFormat.Width = 100;
// Get data, which should be insered into the table.
DataTable data = GetData();
for (int rowIdx = 0; rowIdx <data.Rows.Count; rowIdx++)
    int rowAdvance = 5;
    foreach(DataColumn column in data.Columns)
        // Add name of row.
        if (rowIdx == 0)
            builder.Font.Bold = true;
            builder.Font.Italic = true;
            rowAdvance = 4;
        // Add row data.
        for (int i = rowIdx; i <rowIdx + rowAdvance && i <data.Rows.Count; i++)
    rowIdx += rowAdvance - 1;
// Save output document.
private static DataTable GetData()
    DataTable data = new DataTable("TestData");
    // Add some dummy data.
    for (int i = 0; i <10; i++)
        data.Rows.Add(new object[]
            i.ToString(), string.Format("Project_{0}", i), string.Format("Name_{0}", i), "23133212"
    return data;

Hope this helps.
Regarding the second kind of tables, you can easily achieve this using technique mentioned here:
Please let me know in case of any issues, I will be glad to help you.
Best regards.