Document doc = new Document();
//添加章节
Section sec = doc.AddSection();
//添加段落
Paragraph paragraph = sec.AddParagraph();
//创建域
Field field = new Field(doc);
//设置域的类型
field.Type = FieldType.FieldPage;
// DBNUM1 代表设置样式“一,二,三”
field.Code = " PAGE \\* DBNUM1 \\* MERGEFORMAT";
// Arabic 代表设置样式“1,2,3”
field.Code = " PAGE \\* Arabic \\* MERGEFORMAT ";
//添加域
paragraph.ChildObjects.Add(field);
FieldMark separator = new FieldMark(doc, FieldMarkType.FieldSeparator);
paragraph.ChildObjects.Add(separator);
FieldMark end = new FieldMark(doc, FieldMarkType.FieldEnd);
field.End = end;
paragraph.ChildObjects.Add(end);
//更新域
doc.IsUpdateFields = true;
//保存文件
doc.SaveToFile("result.docx",FileFormat.Docx2013);