2010-08-03 99 views

回答

4

我只是碰巧工作代码,我已经做到这一点在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"; 

还有更多的代码中有比你需要这个特定的任务,但相关线有(即重复在每一页的顶部或东西)的标题是:

sheet.PageSetup.PrintTitleRows = "$3:$5"; 
sheet.PageSetup.PrintTitleColumns = "$A:$B"; 

编辑 - 添加

以下是MSDN文档的链接,以满足您的所有Office Interop需求。

http://msdn.microsoft.com/en-us/library/bb209015(office.12).aspx

6

希望能让你开始。以下伪c#代码可用于向页脚添加文本。只有您必须在宏中执行此操作才能将其完全自动化并识别要添加的文档名称。最后在Document Save期间调用宏以添加页脚文本。

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; 
} 
+0

很酷!我不知道如何在Word中做到这一点,但那是因为我从来没有这样做过。我正在为这个页面添加书签以获得答案,因为我知道我稍后需要它。 +1。 – David 2010-08-03 16:06:49

相关问题