怎么用代码实现下面doc里的页码样式?
temp.zip (38.0 KB)
您可以在以下代码上构建逻辑,以首先在表格单元格中插入Page字段,然后使用TextBox将其放置在Page上的任何位置。
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
Table table = builder.StartTable();
builder.CellFormat.Width = 22;
builder.RowFormat.Height = 72;
builder.InsertCell();
table.AutoFit(AutoFitBehavior.FixedColumnWidths);
builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
builder.CellFormat.Orientation = TextOrientation.Downward;
// Add PAGE field to the Cell.
builder.Write("— ");
builder.InsertField(FieldType.FieldPage, true);
builder.Write(" —");
builder.EndRow();
builder.EndTable();
table.ClearBorders();
Shape textBox = new Shape(doc, ShapeType.TextBox);
textBox.WrapType = WrapType.None;
textBox.Height = 72;
textBox.Width = 22;
textBox.Left = 144;
textBox.Top = 4 * 72;
textBox.AppendChild(table);
builder.InsertNode(textBox);
doc.Save("C:\\temp\\221381\\20.11.docx");