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

Free Support Forum - aspose.com

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<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

1

2

3

…..

ProjectName

PersonalName

Tel

table 2

Name

Unit

Num

Price

Total

Remark

1Test1 400

m

1

10

10

m

2

30

60

m

3

10

30

…….

…….

…….

…….

…….

2Test2 3000

kg

1

20

20

kg

30

30

900

…….

…….

…….

…….

…….

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/mail-merge-with-regions-explained.html

Also, I think information provide in the following forum thread could be useful for you:

http://www.aspose.com/community/forums/229450/nested-table-or-table-row-grouping-with-executewithregions-datatable-method/showthread.aspx#229450

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!!

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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.

builder.MoveToBookmark("table");

// 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.InsertCell();

builder.PushFont();

builder.Font.Bold = true;

builder.Font.Italic = true;

builder.Write(column.ColumnName);

builder.PopFont();

rowAdvance = 4;

}

// Add row data.

for (int i = rowIdx; i < rowIdx + rowAdvance && i < data.Rows.Count; i++)

{

builder.InsertCell();

builder.Write(data.Rows[i][column].ToString());

}

builder.EndRow();

}

rowIdx += rowAdvance - 1;

builder.EndTable();

builder.Writeln();

}

// Save output document.

doc.Save(@"Test001\out.doc");

==================================================================

private static DataTable GetData()

{

DataTable data = new DataTable("TestData");

data.Columns.Add("No");

data.Columns.Add("ProjectName");

data.Columns.Add("PersonalName");

data.Columns.Add("Tel");

// 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:

http://www.aspose.com/community/forums/229450/nested-table-or-table-row-grouping-with-executewithregions-datatable-method/showthread.aspx#229450

Please let me know in case of any issues, I will be glad to help you.

Best regards.