我想在word文档中添加页面边框。这是我的代码
foreach (Microsoft.Office.Interop.Word.Section sectio in document.Sections)
{
//Get the header range and add the header details.
Microsoft.Office.Interop.Word.Border border = sectio.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal];
border.Visible = true;
border.Application.ActiveDocument.Activate();
}
答案 0 :(得分:0)
也许您需要为边框设置样式,宽度和颜色
如果我尝试通过VBA设置它,我会编写这样的代码
With Selection.Borders(wdBorderBottom)
.LineStyle = Options.DefaultBorderLineStyle
.LineWidth = Options.DefaultBorderLineWidth
.Color = Options.DefaultBorderColor
End With
答案 1 :(得分:0)
以下是基于https://www.nuget.org/packages/FreeSpire.Doc/
的解决方案//initialize an instance
Document document = new Document();
//load a document
document.LoadFromFile(@"Example.docx");
Section section = document.Sections[0];
//add page borders with special style and color
section.PageSetup.Borders.BorderType = BorderStyle.DoubleWave;
section.PageSetup.Borders.Color = Color.LightSeaGreen;
//set the spaces between border and text
section.PageSetup.Borders.Left.Space = 50;
section.PageSetup.Borders.Right.Space = 50;
//save
document.SaveToFile("PageBorders.docx", FileFormat.Docx);