Migradoc表头带有表格

9

我可以在Migradoc中创建如下的标题:

  //Create Header
  Paragraph paragraph = section.Headers.Primary.AddParagraph();
  paragraph.AddText("Roto");
  paragraph.Format.Font.Size = 9;
  paragraph.Format.Alignment = ParagraphAlignment.Center;

我可以制作一个简单的表格,如下所示:

  // Create the HEADER table for the top of every page
  this.table = section.AddTable();
  this.table.Style = "Table";
  this.table.Borders.Color = TableBorder;
  this.table.Borders.Width = 0.25;
  this.table.Borders.Left.Width = 0.5;
  this.table.Borders.Right.Width = 0.5;
  this.table.Rows.LeftIndent = 0;

  Column column = this.table.AddColumn("8cm");
  column.Format.Alignment = ParagraphAlignment.Center;

  column = this.table.AddColumn("8cm");
  column.Format.Alignment = ParagraphAlignment.Center;

  // Create the header of the table
  Row row = table.AddRow();
  //row = table.AddRow();
  row.HeadingFormat = true;
  row.Format.Alignment = ParagraphAlignment.Center;
  row.Format.Font.Bold = true;
  row.Shading.Color = TableBlue;

  row.Cells[0].AddParagraph("Rotary");
  row.Cells[0].MergeRight = 1;

  row = table.AddRow();
  row.HeadingFormat = true;
  row.Format.Alignment = ParagraphAlignment.Center;
  row.Format.Font.Bold = true;
  row.Shading.Color = TableBlue;
  row.Cells[0].AddParagraph("Part No.:");
  row.Cells[0].Format.Alignment = ParagraphAlignment.Left;
  row.Cells[1].AddParagraph("Tested by:");
  row.Cells[1].Format.Alignment = ParagraphAlignment.Left;            

  row = table.AddRow();       
  row.Cells[0].MergeRight = 1;

我该如何将表格放到页眉中,使其出现在每一页的顶部?

编辑: 为了使它工作,我进行了更改:

this.table = section.AddTable();

to:

this.table = section.Headers.Primary.AddTable();
1个回答

24
如果你想在每一页上都有相同的页眉:使用section.Headers.Primary.AddTable() 代替 section.Headers.Primary.AddParagraph()
通过为表格的前n行设置 row.HeadingFormat = true;,您将这些行标记为标题行。当表格增长并跨越多个页面时,标题行将在每一页上重复出现(但在“普通”页面正文中,而不是页眉区域)。这是标题行的典型用法。 如果您没有向页眉表添加其他行,则 HeadingFormat = true 不会产生任何效果。

我发誓我尝试了好几次,但都没能让它正常工作。今天早上它终于可以了! - Jeff

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接