Could you please guide me to achieve the below style in aspose word header
image.png (1001 Bytes)
Thanks for your inquiry. To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:
As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.
I have attached the input document and expected output document.
Expected_Output.zip (617.7 KB)
Input Doc.zip (11.7 KB)
You can meet this requirement by using the following code:
Document doc = new Document("D:\\Temp\\Input Doc\\Input Doc.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Table table = builder.StartTable();
builder.InsertCell();
builder.InsertImage("D:\\temp\\Aspose.Words.jpg");
builder.InsertCell();
builder.Write("This is row 1 cell 2");
builder.EndRow();
builder.InsertCell();
builder.Writeln("This is row 2 cell 1");
builder.InsertCell();
builder.Writeln("This is row 2 cell 2");
builder.EndRow();
builder.EndTable();
doc.Save("D:\\Temp\\Input Doc\\18.11.docx");
Thanks for the Replay
My requirement is,
How can we Merge Column1 Row1 and Column1 Row2.
I have updated the given sample code and almost reached my requirement.
Still I have some alignment issues.
Please find the attached wire frame image.
Image aligned left should be vertically filled in R1 C1 and R2 C1
Image aligned center should have some padding from top and right
Dynamic text should be aligned center below the second image
Document doc = new Document("C:\\Input Doc.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
PageSetup ps = builder.PageSetup;
double pageWidth = ps.PageWidth - ps.LeftMargin - ps.RightMargin - ps.Gutter;
Table table = builder.StartTable();
builder.InsertCell().CellFormat.Width = pageWidth * 0.7;
builder.InsertImage("C:\\logo.png");
builder.InsertCell();
//Specify paragraph alignment
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.InsertImage("C:\\text_logo.png");
builder.EndRow();
builder.InsertCell();
builder.InsertCell();
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.Writeln("Title");
builder.EndRow();
builder.EndTable();
VerticallyMergeCells(table.Rows[0].Cells[0], table.Rows[1].Cells[0]);
Cell cell = table.Rows[0].Cells[0];
cell.CellFormat.LeftPadding = 0;
cell.CellFormat.BottomPadding = 0;
// Clear any existing borders from the table.
table.ClearBorders();
// Set a green border around the table but not inside.
table.SetBorder(BorderType.Left, LineStyle.Single, 1.5, Color.Red, true);
table.SetBorder(BorderType.Right, LineStyle.Single, 1.5, Color.Red, true);
table.SetBorder(BorderType.Top, LineStyle.Single, 1.5, Color.Red, true);
table.SetBorder(BorderType.Bottom, LineStyle.Single, 1.5, Color.Red, true);
doc.Save("Doc_18_11_2.docx");<a class="attachment" href="/uploads/default/20578">image.png</a> (1001 Bytes)
Please try using the following code: (see 18.11.zip (19.6 KB))
Document doc = new Document("D:\\Temp\\Input Doc\\Input Doc.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Table table = builder.StartTable();
builder.InsertCell();
builder.InsertCell();
builder.EndRow();
builder.InsertCell();
builder.InsertCell();
builder.EndRow();
builder.EndTable();
table.FirstRow.FirstCell.CellFormat.PreferredWidth = PreferredWidth.FromPercent(70);
table.FirstRow.LastCell.CellFormat.PreferredWidth = PreferredWidth.FromPercent(30);
table.FirstRow.FirstCell.CellFormat.VerticalMerge = CellMerge.First;
table.LastRow.FirstCell.CellFormat.VerticalMerge = CellMerge.Previous;
foreach (Row row in table.Rows)
foreach (Cell cell in row.Cells)
cell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.MoveTo(table.FirstRow.FirstCell.FirstParagraph);
builder.InsertImage("D:\\temp\\aspose.words.jpg", 18, 18);
table.FirstRow.LastCell.FirstParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.MoveTo(table.FirstRow.LastCell.FirstParagraph);
builder.InsertImage("D:\\temp\\aspose.words.jpg", 9, 9);
table.LastRow.LastCell.FirstParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;
builder.MoveTo(table.LastRow.LastCell.FirstParagraph);
builder.Write("Centered Text");
doc.Save("D:\\Temp\\Input Doc\\18.11.docx");
Thanks for the solution. It is working fine.
I have one more doubt.
I want to fit the first Image inside the cell (height only , ie, Image height == cell height)
You can adjust the value of Shape.Height property according to row height. Hope, this helps.