Sha*_*air 6 .net document ms-word footer ms-office
我正在寻找类似于这个的解决方案:http: //esqinc.com/section/products/4/idocid.html
系统所做的是将文档文件名插入文档页脚.如何以编程方式(最好是在.NET中)?
希望这能让你开始.以下伪c#代码可用于向页脚添加文本.只有您必须在宏中执行此操作才能完全自动执行此操作,并确定要添加的文档名称.最后在文档保存期间调用宏以添加页脚文本.
foreach ( Section wordSection in wordDoc.Sections )
{
HeaderFooter footer = wordSection.Footers[ Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary ];
footer.Range.Select( );
footer.Range.Text = footerTxt;
hf.Range.Font.Size = 10;
wordApp.Selection.Paragraphs[ 1 ].Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
wordApp.Selection.Paragraphs[ 1 ].SpaceAfter = 0;
}
Run Code Online (Sandbox Code Playgroud)
我只是碰巧正在编写代码,我已经在 Excel 中从 C# 执行此操作...这是部分的,并且将帮助您开始...
Microsoft.Office.Interop.Excel.Application excelapp = new Microsoft.Office.Interop.Excel.Application();
excelapp.Visible = true;
Microsoft.Office.Interop.Excel._Workbook book = (Microsoft.Office.Interop.Excel._Workbook)excelapp.Workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet); ;
Microsoft.Office.Interop.Excel._Worksheet sheet = (Microsoft.Office.Interop.Excel._Worksheet)book.ActiveSheet;
sheet.get_Range("A1", "N999").Font.Size = "8";
sheet.PageSetup.PaperSize = Microsoft.Office.Interop.Excel.XlPaperSize.xlPaperLegal;
sheet.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape;
sheet.PageSetup.PrintTitleRows = "$3:$5";
sheet.PageSetup.PrintTitleColumns = "$A:$B";
Run Code Online (Sandbox Code Playgroud)
那里的代码比您完成此特定任务所需的代码要多,但是具有标题(或在每个页面顶部重复的内容)的相关行是:
sheet.PageSetup.PrintTitleRows = "$3:$5";
sheet.PageSetup.PrintTitleColumns = "$A:$B";
Run Code Online (Sandbox Code Playgroud)
编辑 - 添加
以下是 MSDN 文档的链接,可满足您的所有 Office Interop 需求。
http://msdn.microsoft.com/en-us/library/bb209015(office.12).aspx