1. 程式人生 > >答題卡作文模塊的一種方法-VSTO

答題卡作文模塊的一種方法-VSTO

In center 屬性 答題 查看 百度 ofo AD http

在開始做之前,首先百度了Word有沒有簡單的生成方法,果然有--頁面布局->稿紙設置->方格式稿紙

技術分享圖片

效果如下圖所示。很規範,但是不是答題卡所需要的,因為這樣會把所有頁面都設置為這樣的稿紙。

技術分享圖片

搜索了很久,沒有找到現成的方法,但是受到了一些啟示,因此我做出來以下效果的作文表格:

技術分享圖片

和作文紙很像了,可以根據具體規格稍加調整即可用了。具體方法很簡單,就是表格操作。

具體操作:

  1. 先插入1列多行的表格

    技術分享圖片

  2. 再在一行中插入1行多列

  3. 技術分享圖片

  4. 調整外表格的表格屬性,選中外表格不太好選中,我是點擊右下角選中的

    技術分享圖片

    技術分享圖片

    技術分享圖片

  5. 然後調整方格大小,並插滿一行

    技術分享圖片

  6. 復制一行到其他行,

    技術分享圖片

  7. 最後一步就是把外表格的邊框去掉,選中不好選,我是通過拉大最後一行選中外表格,最後得到完美表格

    技術分享圖片

最後,根據這樣的方法,可以利用VSTO直接生成作文表格,代碼如下:

 1 public void AddWritten(Range range)
 2         {
 3             range.MoveEnd();
 4             Document doc = Globals.ThisAddIn.Application.ActiveDocument;
 5             Table t = range.Tables.Add(range, 10, 1);
 6             foreach (Row item in t.Rows)
7 { 8 item.Height = 32; 9 Range rowRange = item.Cells [1].Range; 10 Table rowT = rowRange.Tables.Add(rowRange, 1, 17); 11 rowT.Rows.Height = 24; 12 rowT.Columns.Width = 24; 13 rowT.Borders[WdBorderType.wdBorderTop].LineStyle = WdLineStyle.wdLineStyleSingle;
14 rowT.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleSingle; 15 rowT.Borders[WdBorderType.wdBorderLeft].LineStyle = WdLineStyle.wdLineStyleSingle; 16 rowT.Borders[WdBorderType.wdBorderRight].LineStyle = WdLineStyle.wdLineStyleSingle; 17 rowT.Borders[WdBorderType.wdBorderVertical].LineStyle = WdLineStyle.wdLineStyleSingle; 18 rowT.Borders[WdBorderType.wdBorderHorizontal].LineStyle = WdLineStyle.wdLineStyleSingle; 19 item.Cells.VerticalAlignment =WdCellVerticalAlignment.wdCellAlignVerticalCenter; 20 } 21 doc.Paragraphs.Add(); 22 23 }

答題卡作文模塊的一種方法-VSTO