2010-08-03 98 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

相關問題