Hi-
For our grid based reports we want to provide the user ability to export the data to a word document. The generated word document should support the following features
- For each page add custom header and footer both of which would have dynamic contents including page number
- At beginning of every page in the word document the grid column headers should be displayed. For example if my report is showing customer details and has CustomerName, Street, City, State and Zipcode, these column names should be repeated at the start of each new page.
- Ability to specify paper size - height and width
- Paginate report based on the page size
- Specify margins - top,bottom,left,right
Can you please point to any samples/discussions related to similar requirements that have been addressed.
Thanks,
Pramod
Hi
Pramod,
Thanks for your inquiry and sorry for the delayed response.
Sure, you can achieve this by using MailMerge feature. With Aspose.Words you can generate documents from templates with mail merge fields. The data from an external source like a database or file can be placed into these fields and formatted, and the resulting document is saved in the folder you specify.
- I would suggest you please read the following article on Creating Headers Footers using DocumentBuilder:
https://docs.aspose.com/words/net/working-with-headers-and-footers/
Moreover, you can use the following code snippet to be able to insert Page numbers in Headers or Footers:
// Create new Docuemnt and DocumentBuilder
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert PAGE field into the header and footer
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Write("- ");
builder.InsertField("PAGE", null);
builder.Write(" -");
- I think, you can easily achieve this by using mail merge with regions. You can specify ‘Repeat as Header row at the top of each page’ option to the first row of table region in your template. Moreover, I have attached a sample template document for your reference. Please try running the following code against it:
Document doc = new Document(@"C:\test\template.docx");
DataTable dt = new DataTable("tbl");
dt.Columns.Add("c1");
dt.Columns.Add("c2");
dt.Columns.Add("c3");
DataRow dataRow;
for (int row = 0; row < 100; row++)
{
dataRow = dt.NewRow();
dataRow["c1"] = "R:" + row + " C:0";
dataRow["c2"] = "R:" + row + " C:1";
dataRow["c3"] = "R:" + row + " C:2";
dt.Rows.Add(dataRow);
}
doc.MailMerge.ExecuteWithRegions(dt);
doc.Save(@"C:\test\out.docx");
-
You can achieve this by using PageSetup class. Also, I would suggest you please read the following article on specifying page properties in inches:
https://reference.aspose.com/words/net/aspose.words/convertutil/
-
Could you please explain your question in more detail? We will take a closer look at this and provide you more information.
-
You can try specifying appropriate values to PageSetup.TopMargin, PageSetup.LeftMargin, PageSetup.RightMargin and PageSetup.BottomMargin properties.
Please let me know if I can be of any further assistance.
Best Regards,