在開始作以前,首先百度了Word有沒有簡單的生成方法,果真有--頁面佈局->稿紙設置->方格式稿紙佈局
效果以下圖所示。很規範,可是不是答題卡所須要的,由於這樣會把全部頁面都設置爲這樣的稿紙。spa
搜索了好久,沒有找到現成的方法,可是受到了一些啓示,所以我作出來如下效果的做文表格:3d
和做文紙很像了,能夠根據具體規格稍加調整便可用了。具體方法很簡單,就是表格操做。code
具體操做:blog
先插入1列多行的表格get
再在一行中插入1行多列頁面佈局
調整外表格的表格屬性,選中外表格不太好選中,我是點擊右下角選中的it
而後調整方格大小,並插滿一行io
複製一行到其餘行,class
最後一步就是把外表格的邊框去掉,選中很差選,我是經過拉大最後一行選中外表格,最後獲得完美表格
最後,根據這樣的方法,能夠利用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 }