How do i repeat template with new data

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.

Hi

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.

Hi
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.

Hi
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);
    doc.Save(@"249_97718_jonathanh\out.doc");
}
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;
    }
    else
    {
        EndIndex = Data.Length;
    }
    //insert values into table
    table.FirstRow.Cells[2].FirstParagraph.Remove();
    for (int i = StartIndex; i < EndIndex; i++)
    {
        Paragraph paragraph = new Paragraph(builder.Document);
        Run run = new Run(builder.Document);
        run.Text = Data[i];
        paragraph.AppendChild(run);
        table.FirstRow.Cells[2].Paragraphs.Add(paragraph);
    }
    Paragraph par = new Paragraph(builder.Document);
    CompositeNode node = builder.CurrentParagraph.ParentNode;
    node.InsertAfter(par, builder.CurrentParagraph);
    node.InsertAfter(table, builder.CurrentParagraph);
    builder.MoveTo(par);
    if (EndIndex != Data.Length)
    {
        //insert page break and run this method again
        builder.InsertBreak(BreakType.PageBreak);
        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.

Hi
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;
}
else
{
    EndIndex = Data.Length;
}

See the following link to learn how to merge documents.
https://docs.aspose.com/words/net/insert-and-append-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
Trade1
Trade2
Trade3
Trade4
Trade5
Trade6
Trade7
Trade8
Trade9
Trade10
Generic1
Generic2
1
2
3
10/10/2007 4:04:20 PM 1
2
10/10/2007 4:04:20 PM
Trade Special Generic Special 7 11/10/2007 4:04:20 PM 3
4
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.

Hi
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.

Hi
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");
table.Columns.Add("Trade");
table.Columns.Add("GenericName");
table.Columns.Add("Date");
table.Columns.Add("Date2");
//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();
    table.Rows.Add(row);
}
//open template document
Document doc = new Document(@"273_97718_jonathanh\in.doc");
//execute mailmerge
doc.MailMerge.ExecuteWithRegions(table);
//save result.
doc.Save(@"273_97718_jonathanh\out.doc");

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.

This is not the solution.
We can’t change any cell width and height.Template should remain Fixed.
What you have suggested if we add more trade names then Cell start expanding which is not desirable.
Suppose few Trade Names added to your code then Cell starts Expanding but idealy table template should go to next page with overflow data.
If you have refer the two documents(WantedOutput.doc , ExistingOutput.doc) which i had attached then you can understand the problem.
ExistingOutput.doc is what that you have suggested.(if TradeName increases then Cell starts expanding, which is not desirable)
WantedOutput.doc is what i required.(If TradeName increase the whole template is repeat with overflow data)
Please go through the both documents and table which i have given to you in last posts to properly understand the problem.
This becomes a very hot issue for our project.kindly give some good attention to it.
Thanks.

Hi

I have seen these documents. And I think that I cannot help you further. To be able to help you I need to have code that you use to perform mail merge, some data that you use and your template but not the result document. Right now I can see no way how I can help you.

Best regards,

Please find the code…

DataTable table = new DataTable("table");
table.Columns.Add("Trade");
table.Columns.Add("GenericName");
table.Columns.Add("Date");
table.Columns.Add("Date2");
DataRow row = table.NewRow();
row[0]=@"Trade1\nTrade2\nTrade3\nTrade4\nTrade5\nTrade6\n
Trade7\nTrade8\nTrade9\nTrade10\nTrade11\nTrade12\nTrade13\nTrade14\nTrade15\nTrade16\nTrade17";
row[1] = "Generic1\nGeneric2";
row[2] = DateTime.Now.ToString();
row[3] = DateTime.Now.ToString();
table.Rows.Add(row);
DataRow row1 = table.NewRow();
row1[0]= "Trade Special";
row1[1] = "Generic Special";
row1[2] = DateTime.Now.ToString();
row1[3] = DateTime.Now.ToString();
table.Rows.Add(row1);
//open template document
Document doc = new Document(@"Template.doc");
//execute mailmerge
doc.MailMerge.ExecuteWithRegions(table);
//save result.
doc.Save(@"ExistingOutput.doc");

I have attached Template.doc in this post and for ExistingOutput.doc you can refer my last post in this series.
For WantedOutput.doc you can refer last to last post.

Hi
Please reattach your template.
Best regards.

I have attached the Template in last post.

Hi
Yes, I see attachment now. Unfortunately, I can’t help you with this issue. It is not trivial task. It’s impossible to determine whether the text will fit in the cell or not. You can manually calculate how much rows can be inserted into the cell and split your data before mail merge. Also see the following link. Maybe this information will help you to find solution.
Best regards.

A post was split to a new topic: Perform mail merge with data