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

Free Support Forum - aspose.com

How do i repeat template with new data

I have created one template (See attached doc) in which bold Labels are fixed title and others are data.
If data overflows then i want to repeat the same template in the next page with overflow data.
Can you please tell me how can i do that. I want to do this dynamically not using mail merge.
Exp: In the attached doc if Trade Name is around 50 and 10 are coming in first page then in second page next 10 should show with same template. it should cover the whole page and then grow to second page.

Thanks for your request. I think that you should use MailMerge to achieve this. See the following links.
How to prepare a template document
How to perform mail merge
I hope that it will help you.
Best regards.

I can’t use mail merge now because in my project several reports need to be shown in one document(word file) and this requirement is for only one file, all other files have been developed.
can you please tell me the other way, how i can create this using aspose APIs dynamically.

I am still convinced that you should use mail merge. After mail merge you can insert the document into another document. See the following link.
But if you can’t use this feature then you can build your template programmatically using DocumentBuilder class. See the attachment.
Best regards.

I am not able to access the attachment.

Can you give me your e-mail? I will send the file to you.
Best regards.

my email id is :- gauravg@relsys.net

I have send file by E-Mail.
Best regards.

I think you didn’t get my question. this form i have already created.
My question was if Trade Name increases instead of Cell expand it should go to the next page with the template(Form should repeat there with new TradeName values).
I want generalize solution as any cell data can expand.
I have attached the sample file please go through it.It will clarify my problem.


Thanks for additional information. I think that you should insert the header of your template into the table cell; then set “Table properties”/“Row”/“Repeat as header row at the top of each page” = true to repeat your header at each page. See the attachment.

Also, please, do what you want using MS Word and attach the created document here.

Best regards.

I am very sorry you didn’t understand my problem.
Still it is not solved please find attached word doc containing my problem.
I have added a file SampleProb.doc.

Thanks for additional information. I will try to find solution for you. Please expect a reply soon. Also, please, tell me why you don’t want use mail merge. I think that you can easy solve this task using mail merge.
Best regards.

Acutally I need to show twenty of reports with in a word file and most of them are generated dynamically(without mailmerge).The pending reports are also implemented without these features so just wanna to add one feature so that it should start working.
The release date is very soon.

I have tried to find solution for you and created the following code. I have used your document as template (in.doc).

public void InsertDataIntoTemplate_97718()
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    //create array of values
    string[] arr = new string[98];
    for (int i = 0; i < arr.Length; i++)
        arr[i] = "Trade" + i.ToString();
    InsertTableWithData(arr, 0, builder);
private void InsertTableWithData(string[] Data, int StartIndex, DocumentBuilder builder)
    //open template document
    Document doc = new Document(@"249_97718_jonathanh\in.doc");
    NodeImporter importer = new NodeImporter(doc, builder.Document, ImportFormatMode.KeepSourceFormatting);
    //get table from document
    Table table = (Table)importer.ImportNode(doc.FirstSection.Body.Tables[0], true);
    //calculate end index. We will insert 10 rows into cell
    int EndIndex = 0;
    if (Data.Length - StartIndex > 10)
        EndIndex = StartIndex + 10;
        EndIndex = Data.Length;
    //insert values into table
    for (int i = StartIndex; i < EndIndex; i++)
        Paragraph paragraph = new Paragraph(builder.Document);
        Run run = new Run(builder.Document);
        run.Text = Data[i];
    Paragraph par = new Paragraph(builder.Document);
    CompositeNode node = builder.CurrentParagraph.ParentNode;
    node.InsertAfter(par, builder.CurrentParagraph);
    node.InsertAfter(table, builder.CurrentParagraph);
    if (EndIndex != Data.Length)
        //insert page break and run this method again
        InsertTableWithData(Data, EndIndex, builder);

I hope that it will help you to solve your problem. Let me know if it will not help you.
Best regards.

It Still doesn’t solve my problem.
What you have suggested that we manually take care of rows with in a cell and if it grows then go to next page …suppose we have set after ten rows it should go to the next page but if first row is very large and cover the whole cell then it won’t help us. Template can be fixed but what i want that if cell is filled then dynamically it should go to the next page with whole template repeat.
If it is possible in mail merge then i can go for that also…as i have read mail merge options but couldn’t find anything which can solve my problem. I want to print report having template with 11 rows and 5 columns all are filled from different tables. Reference document is attached.
Apart from this i also need the solution how we can merge this document into the existing one.

This code is given as example. I think you can change the following code with code that will calculate how many rows will be inserted into cell.

int EndIndex = 0;
if (Data.Length - StartIndex > 10)
    EndIndex = StartIndex + 10;
    EndIndex = Data.Length;

See the following link to learn how to merge documents.
Also see the following link.

Best regards.

It still doesn’t solve my problem. Now I am using mail merge.
Problem Statement: In template, if data in any cell(may be one or more) expands then instead of cell height expansion i want the overflow data should come in next page. Template has to be fixed as it has to go to regulatory authority.
Following is the example for your reference
I am having the data table entry…which i am passing to mailmerge.executeregion()

Trade Name Generic Name Event Date Outcome Date2
10/10/2007 4:04:20 PM 1
10/10/2007 4:04:20 PM
Trade Special Generic Special 7 11/10/2007 4:04:20 PM 3
11/10/2007 4:04:20 PM

Follwoing is the output that comes while using Mailmerge see Attached Doc 1 (ExistingOutput.doc)
What i want is in Attached Doc 2 (WantedOutput.doc)
The difference is that in first document the TradeName cell and Event Cell is expand to incorporate tradename9 and tradename10 but in wanted document the whole template is repeat isteat of expanding the cell.
My template cell width need to be fixed as it goes to regulatory authorities.
please look the Existing output in the last post…as i am not able to attach two document here.

Thanks for additional information. Please attach your template and some code that you use to perform mail merge.
Best regards.

I have already given you two document :
ExistingOutput.doc and WantedOutput.doc
ExistingOutput will consist of report which currently mail merge giving me.
WantedOutput will consist of report which i want.
I have already given you my table which i m passing to the mailmerge.executeregion() function. please go through the previous post.
WantedOutput is attached in last post. ExistingOutput i told you that you can get from last to last post as two document attachment is not supported by Aspose.
for your reference i am again attaching the ExistingOutput.
Can you please wrap up this issue as soon as possible because deadline is already passed and it becomes very very high priority issue for our project.

I tried to use the following code and the attached template document and got good result on my side. I have manually created a table with data, but you should use your data.

//create datatable
DataTable table = new DataTable("table");
//add some data 
for (int i = 0; i < 10; i++)
    DataRow row = table.NewRow();
    row[0] = "Trade1\nTrade2\nTrade3\nTrade4\nTrade5\nTrade6\nTrade7\nTrade8\nTrade9\nTrade10";
    row[1] = "Generic1\nGeneric2";
    row[2] = DateTime.Now.ToString();
    row[3] = DateTime.Now.ToString();
//open template document
Document doc = new Document(@"273_97718_jonathanh\in.doc");
//execute mailmerge
//save result.

If you provide me the code that you use to perform mail merge and the template file I will analyze your code and template and try to help you.
Best regards.