# word04.rb.txt: ruby script (encoding: Windows-31J) # z_word04.doc を出力 # 2段組の文書を作成 # 文字の書体、大きさ、太字の指定を行う # 箇条書きを行う require "wrdap" # 電車の路線別の駅名一覧データ line1 = %w(◇山手線 東京 有楽町 新橋 浜松町 田町 品川 大崎 五反田) + %w(目黒 恵比寿 渋谷 原宿 代々木 新宿 新大久保 高田馬場 目白) + %w(池袋 大塚 巣鴨 駒込 田端 西日暮里 日暮里 鶯谷 上野 御徒町 秋葉原 神田) line2 = %w(◇武蔵野線 府中本町 北府中 西国分寺 新小平 新秋津) + %w(東所沢 新座 北朝霞 西浦和 武蔵浦和 南浦和 東浦和 東川口) + %w(南越谷 越谷レイクタウン 吉川 吉川美南 新三郷 三郷 南流山) + %w(新松戸 新八柱 東松戸 市川大野 船橋法典 西船橋) filename = "z_word04.doc" if test(?e, filename) # z_word01.docが存在するなら削除 File.unlink(filename) end wrd = Wrdap.new wrd.opens(filename) do |doc| doc.PageSetup.TextColumns.SetCount(2) # 2段組に設定 doc.PageSetup.TextColumns.LineBetween = true # 段組境界線を引く slc = doc.Application.Selection i = 1 # iに段落番号を記録 line_name = line1.shift # 電車の路線名 slc.TypeText line_name # 路線名入力 slc.TypeParagraph() # エンターキーを押すことに相当 rng = doc.Paragraphs(i).Range rng.Font.Name = "MS ゴシック" rng.Font.Size = 12.0 #文字の大きさを12ポイントにする rng.Font.Bold = true # 太字にする i += 1 # 段落番号を1つ増やす(次の段落の番号) doc.Paragraphs(i).Range.ListFormat.ApplyBulletDefault # 箇条書きに切り替え while station_name = line1.shift # 駅名の読み込み slc.TypeText station_name slc.TypeParagraph() i += 1 end rng = doc.Paragraphs(i).Range rng.Style = WdStyleNormal # 箇条書きを解除(標準スタイルに戻す) rng.ParagraphFormat.Alignment = WdAlignParagraphLeft # 左揃えにする line_name = line2.shift slc.TypeText line_name # 路線名入力 slc.TypeParagraph() # エンターキーを押すことに相当 rng = doc.Paragraphs(i).Range rng.Font.Name = "MS ゴシック" rng.Font.Size = 12.0 rng.Font.Bold = true rng.Collapse('Direction'=>WdCollapseStart) # 範囲解除&範囲先頭に移動 rng.InsertBreak('Type'=>WdColumnBreak) # 段区切りを挿入 i += 1 # 段落番号を1つ増やす(次の段落の番号) doc.Paragraphs(i).Range.ListFormat.ApplyBulletDefault # 箇条書きに切り替え while station_name = line2.shift slc.TypeText station_name slc.TypeParagraph() i += 1 end rng = doc.Paragraphs(i).Range rng.Style = WdStyleNormal # 箇条書きを解除(標準スタイルに戻す) rng.ParagraphFormat.Alignment = WdAlignParagraphLeft doc.ActiveWindow.View.Type = WdPrintView # 印刷レイアウトモード doc.save end wrd.quit __END__ ○ InsertBreak() の引数として指定できる定数  引数として、挿入される文書区切りの種類を指定する。  指定しない時は、「WdPageBreak: 挿入位置で改ページ」が指定されたものとみなされる。  次のものが指定できる。ただし、インストールされている言語(日本語等)によっては使えないものがあるので注意。 ・WdSectionBreakNextPage 2 次のページ上にセクション区切りを挿入 ・WdSectionBreakContinuous 3 改ページなしで新しいセクションを開始 ・WdSectionBreakEvenPage 4 セクション区切りを挿入し、次の偶数ページから次のセクションを開始   セクション区切りを偶数ページに挿入した場合、次の奇数ページは空白になる。 ・WdSectionBreakOddPage 5 セクション区切りを挿入し、次の奇数ページから次のセクションを開始   セクション区切りを奇数ページに挿入した場合、次の偶数ページは空白になる。 ・WdLineBreak 6 改行 ・WdPageBreak 7 挿入位置で改ページ ・WdColumnBreak 8 挿入位置に段区切りを挿入 ・WdLineBreakClearLeft 9 改行 ・WdLineBreakClearRight 10 改行 ・WdTextWrappingBreak 11 現在の行を終了し、画像、表、またはその他の項目の下に続きの文字列を配置する。   続きの文字列の開始位置は、左端または右端に揃えられた表を含まない、次の空白行。