[編程語言][.NET Office][Word]設置佈局
文字方向
紙張大小
屬性: Document.PageSetup.PaperSize
註釋: 設置Document.PageSetup.PageHeight或Document.PageSetup.PageWidth屬性會將Document.PageSetup.PaperSize屬性更改爲
枚舉值 | 枚舉名稱 | 描述 |
---|---|---|
0 | wdPaper10x14 | |
1 | wdPaper11x17 | |
2 | wdPaperLetter | |
3 | wdPaperLetterSmall | |
4 | wdPaperLegal | |
5 | wdPaperExecutive | |
6 | wdPaperA3 | |
7 | wdPaperA4 | |
8 | wdPaperA4Small | |
9 | wdPaperA5 | |
10 | wdPaperB4 | |
11 | wdPaperB5 | |
12 | wdPaperCSheet | |
13 | wdPaperDSheet | |
14 | wdPaperESheet | |
15 | wdPaperFanfoldLegalGerman | |
16 | wdPaperFanfoldStdGerman | |
17 | wdPaperFanfoldUS | |
18 | wdPaperFolio | |
19 | wdPaperLedger | |
20 | wdPaperNote | |
21 | wdPaperQuarto | |
22 | wdPaperStatement | |
23 | wdPaperTabloid | |
24 | wdPaperEnvelope9 | |
25 | wdPaperEnvelope10 | |
26 | wdPaperEnvelope11 | |
27 | wdPaperEnvelope12 | |
28 | wdPaperEnvelope14 | |
29 | wdPaperEnvelopeB4 | |
30 | wdPaperEnvelopeB5 | |
31 | wdPaperEnvelopeB6 | |
32 | wdPaperEnvelopeC3 | |
33 | wdPaperEnvelopeC4 | |
34 | wdPaperEnvelopeC5 | |
35 | wdPaperEnvelopeC6 | |
36 | wdPaperEnvelopeC65 | |
37 | wdPaperEnvelopeDL | |
38 | wdPaperEnvelopeItaly | |
39 | wdPaperEnvelopeMonarch | |
40 | wdPaperEnvelopePersonal | |
41 | wdPaperCustom |
紙張方向
屬性: Document.PageSetup.Orientation
枚舉值 | 枚舉名稱 | 描述 |
---|---|---|
0 | wdOrientPortrait | 縱向 |
1 | wdOrientLandscape | 橫向 |
頁邊距
屬性:
- Document.PageSetup.TopMargin
- Document.PageSetup.BottomMargin
- Document.PageSetup.LeftMargin
- Document.PageSetup.RightMargin
欄
屬性:
- Document.PageSetup.TextColumns.Count
- Document.PageSetup.TextColumns.EvenlySpaced
- Document.PageSetup.TextColumns.FlowDirection
- Document.PageSetup.TextColumns.LineBetween
- Document.PageSetup.TextColumns.Spacing
- Document.PageSetup.TextColumns.Width
函數: - Document.PageSetup.TextColumns.SetCount(int NumberColumns)
- Document.PageSetup.TextColumns.Add(ref object Width, ref object Spacing, ref object EvenlySpaced)
- Document.PageSetup.TextColumns.GetEnumerator()
每欄的屬性:
- MSWord.TextColumn.Width
- MSWord.TextColumn.SpaceAfter
獲取欄數
通過獲取屬性Document.PageSetup.TextColumns.Count即可。
設置或取消分割線
如果設置屬性Document.PageSetup.TextColumns.LineBetween爲True(-1),則顯示分割線。
如果設置屬性Document.PageSetup.TextColumns.LineBetween爲False(0),則隱藏分割線。
設置欄的方向
如果設置Document.PageSetup.TextColumns.FlowDirection屬性爲MSWord.WdFlowDirection.wdFlowLtr,則欄從左到右。
如果設置Document.PageSetup.TextColumns.FlowDirection屬性爲MSWord.WdFlowDirection.wdFlowRtl,則欄從右到左。
設置欄寬度和欄間距
欄寬相等
需要注意下面兩個問題:
- SetCount()函數是按照當前Spacing的值重新分配欄寬度的。
- Width和Spacing這兩個的值是按照最後分配的那個屬性的值來確定另一個屬性的值的。
設置等寬欄有三種方法:
- 如果需要將頁面分成指定數目的等寬欄時,可以調用SetCount()函數。但是需要在調用SetCount()之前設置Spacing的值,或者在調用SetCount()之後設置Width的值。
- 如果需要將當前頁面的欄設置成等寬的,只需設置Width屬性或Spacing屬性。
- 設置EvenlySpaced屬性的值爲True(-1),也可以將當前頁面的欄設置成等寬的。需要注意的是,EvenlySpaced的值是依據第一欄的SpaceAfter屬性的值來設置Spacing屬性的值,然後再依據Spacing屬性的值來確定欄的寬度Width屬性的值的。
欄寬不相等
- 可以通過調用Add()函數添加一個新欄。需要注意的是Add()函數的第三個參數EvenlySpaced的值永遠需要傳入False(0)。此時,會將EvenlySpaced屬性的值設置爲False(0)。
- 如果需要改變某一欄的寬度或欄間距,可以通過foreach語句遍歷,或是通過調用GetEnumerator()函數得到IEnumerator來遍歷,以獲取到指定列的欄的TextColumn對象,然後再設置其Width屬性或SpaceAfter屬性。需要注意的是,最後一欄之後是沒有欄間距的,故不能對其設置SpaceAfter屬性。
分隔符
通過調用MSWord.Range.InsertBreak(ref object Type)函數實現,參數可以傳入MSWord.WdBreakType枚舉中的任何一個
枚舉值 | 枚舉名稱 | 描述 |
---|---|---|
2 | wdSectionBreakNextPage | 分節符在下一頁。 |
3 | wdSectionBreakContinuous | 新節不包含相應分頁符。 |
4 | wdSectionBreakEvenPage | 使下一節從下一偶數頁開始的分節符。如果分節符落入偶數頁,則 Word 將下一奇數頁留爲空白。 |
5 | wdSectionBreakOddPage | 使下一節從下一奇數頁開始的分節符。如果分節符落入奇數頁,則 Word 將下一偶數頁留爲空白。 |
6 | wdLineBreak | 換行符。 |
7 | wdPageBreak | 插入點處的分頁符。 |
8 | wdColumnBreak | 插入點處的分欄符。 |
9 | wdLineBreakClearLeft | 換行符。 |
10 | wdLineBreakClearRight | 換行符。 |
11 | wdTextWrappingBreak | 結束當前行,並強制文字在圖片、表格或其他項目的下方繼續。文字將在下一個空行(且該空行不包含與左邊距或右邊距對齊的表格)上繼續。 |
行號
屬性:
wordDocument.PageSetup.LineNumbering.Active
wordDocument.PageSetup.LineNumbering.CountBy
wordDocument.PageSetup.LineNumbering.DistanceFromText
wordDocument.PageSetup.LineNumbering.RestartMode
wordDocument.PageSetup.LineNumbering.StartingNumber
設置是否顯示行號
如果將Document.PageSetup.LineNumbering.Active屬性設置爲True(-1),則將顯示行號;如果將該屬性設置成False(0),則不顯示行號。
設置顯示行號的間隔數
Document.PageSetup.LineNumbering.CountBy屬性指示行號間隔數。如果其值爲5,則在5的整數倍顯示行號。
設置行號位置
Document.PageSetup.LineNumbering.DistanceFromText屬性指示行號的右邊緣和左邊的緣與文檔文字之間的距離。
設置排序方式
Document.PageSetup.LineNumbering.RestartMode屬性指示行號的排序方式。該屬性的值可被賦值爲MSWord.WdNumberingRule枚舉類型,其枚舉值可爲:
枚舉值 | 枚舉名稱 | 描述 |
---|---|---|
0 | wdRestartContinuous | 連續分配編號。 |
1 | wdRestartSection | 重設每一節的節號。 |
2 | wdRestartPage | 重設每一頁的頁碼。 |