四、選擇題的寫入及排版
如果四個選項按四段(行)進行排版,則只要通過調(diào)用前面所定義的兩個過程就能實現(xiàn),但四個選項要按兩行排版則有兩種方法可供選擇:一是分節(jié)分欄法:將四個選項按四段寫入Word文檔,并將它們設(shè)置成單獨的一節(jié),再采用分成兩欄的方法實現(xiàn);二是直接寫入排版法:在同一行的兩個選項之間插入若干個制表位實現(xiàn)對齊,編程中將涉及寫入點的定位問題。
1、分節(jié)分欄法
選擇題寫入Word文檔及排版操作在自定義過程insSelect中實現(xiàn),傳入?yún)?shù)mObj內(nèi)封裝了一道選擇題;題號通過參數(shù)n傳入;參數(shù)max傳入的值是選項內(nèi)容字符數(shù)的臨界值,即當四個選項內(nèi)容中字符數(shù)最多者如果超過了max,則四個選項排版成四段(行),否則排成兩行。其中用到的函數(shù)maxLen(mObj)返回值表示選擇題mObj的四個選項內(nèi)容中字符數(shù)的最大值。
Private Sub insSelect(mObj As Choice, ByRef n As Integer, max As Integer)
insTabIndent mObj.Sentence, n '寫入題干內(nèi)容及題號
If maxLen(mObj) > max Then'按四段(行)并采用左縮進及懸掛縮進寫入
insLeftAndHangingIndent "A) " + mObj.ChoiceA
insLeftAndHangingIndent "B) " + mObj.ChoiceB
insLeftAndHangingIndent "C) " + mObj.ChoiceC
insLeftAndHangingIndent "D) " + mObj.ChoiceD
ActiveDocument.Content.InsertParagraphAfter
n = n + 1
Else '選項按縮進一個制表位形式寫入,為后面的分節(jié)分欄做準備
Set tempRange = ActiveDocument.Content
tempRange.Collapse Direction:=wdCollapseEnd
tempRange.InsertAfter vbTab & "A) " & mObj.ChoiceA
tempRange.InsertParagraphAfter
tempRange.InsertAfter vbTab & "B) " & mObj.ChoiceB
tempRange.InsertParagraphAfter
tempRange.InsertAfter vbTab & "C) " & mObj.ChoiceC
tempRange.InsertParagraphAfter
tempRange.InsertAfter vbTab & "D) " & mObj.ChoiceD
tempRange.InsertParagraphAfter
tempRange.Font.Name = "宋體"
tempRange.Font.Size = 12'小四
n = n + 1 '題號增1,為寫入下一題做準備
tempRange.Select '選定四個選項所在的區(qū)域
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type <> wdPrintView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
'在選定區(qū)域的起始位置和末尾位置插入分節(jié)符
ActiveDocument.Range(Start:=Selection.Start, End:=Selection.Start). _
InsertBreak Type:=wdSectionBreakContinuous
Selection.Start = Selection.Start + 1
ActiveDocument.Range(Start:=Selection.End, _
End:=Selection.End).InsertBreak Type:=wdSectionBreakContinuous
'將選定的文本分成兩欄
With Selection.PageSetup.TextColumns
.SetCount NumColumns:=2
.EvenlySpaced = True
.LineBetween = False
.Width = CentimetersToPoints(6.95)
.Spacing = CentimetersToPoints(0)
End With
ActiveDocument.Content.InsertParagraphAfter
End If
End Sub
相關(guān)推薦:北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |