object Missing = System.Reflection.Missing.Value;
ApplicationClass wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
wordApp.Visible = true;
_Document doc = wordApp.Documents.Add(ref Missing, ref Missing, ref Missing, ref Missing);
doc.Activate();
//设置页面总体格式
doc.PageSetup.PageHeight = 1040.0F;
doc.PageSetup.PageWidth = 734.286F;
doc.PageSetup.TopMargin = 37.142F;
doc.PageSetup.BottomMargin = 37.142F;
doc.PageSetup.LeftMargin = 40;
doc.PageSetup.RightMargin = 40;
// 打印出标题
wordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
wordApp.Selection.Font.Bold = (int)WdConstants.wdToggle;
wordApp.Selection.Font.Size = 18;
wordApp.Selection.Font.Name = "宋体";
wordApp.Selection.TypeText("XXXXXX");
wordApp.Selection.TypeParagraph();
//打印出(A)卷 08/09学年 第二学期 班级: 姓名: 学号:
wordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
wordApp.Selection.Font.Bold = 0;
wordApp.Selection.Font.Size = 12;
wordApp.Selection.TypeText("(A)卷 08/09学年 第二学期 班级: 姓名: 学号: ");
wordApp.Selection.TypeParagraph();
//打印出…………………………………装……………………………订…………………………线……………………………………………
wordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
wordApp.Selection.Font.Bold = 0;
wordApp.Selection.Font.Size = 12;
wordApp.Selection.TypeText("…………………………………装……………………………订…………………………线……………………………………………");
wordApp.Selection.TypeParagraph();
//插入表格
Range range = doc.Content;
range.Select();
object lastPositioin = doc.Characters.Count - 1;
range = doc.Range(ref lastPositioin, ref lastPositioin);
doc.Tables.Add(range, 1, 8, ref Missing, ref Missing);
//向表格中添加内容
Cell cell = doc.Tables[1].Cell(1, 1);
cell.Range.Text = "适用专业:";
cell = doc.Tables[1].Cell(1, 3);
cell.Range.Text = "考核性质:";
cell = doc.Tables[1].Cell(1, 5);
cell.Range.Text = "命题教师";
cell = doc.Tables[1].Cell(1, 7);
cell.Range.Text = "考试时间";
//再添加一个表格
lastPositioin = doc.Characters.Count - 1;
range = doc.Range(ref lastPositioin, ref lastPositioin);
doc.Tables.Add(range, 5, 10, ref Missing, ref Missing);
//在表格中添加内容
cell = doc.Tables[1].Cell(2, 1);
cell.Range.Text = "题号";
cell = doc.Tables[1].Cell(3, 1);
cell.Range.Text = "得分";
cell = doc.Tables[1].Cell(4, 1);
cell.Range.Text = "评阅人";
cell = doc.Tables[1].Cell(5, 1);
cell.Range.Text = "复核人";
//保存和退出
object path = @"D:/database/123.doc";
doc.SaveAs(ref path, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing);
doc.Close(ref Missing, ref Missing, ref Missing);
wordApp.Quit(ref Missing, ref Missing, ref Missing);