111,109
社区成员




object Nothing = System.Reflection.Missing.Value;
object missing = System.Reflection.Missing.Value;
//创建Word文档
Word.Application wordApp = new Word.ApplicationClass();
wordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone; //重要非常重要!!!!!!否则程序会异常,应为在工作的过程中,默认要用户交互,可是用户确没有交互,所以就出错了
Word.Document wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
wordApp.Visible = false;
wordDoc.Activate();
//设置文档宽度
wordApp.Selection.PageSetup.LeftMargin = wordApp.CentimetersToPoints(float.Parse("2"));
wordApp.ActiveWindow.ActivePane.HorizontalPercentScrolled = 11;
wordApp.Selection.PageSetup.RightMargin = wordApp.CentimetersToPoints(float.Parse("2"));
Object start = Type.Missing;
Object end = Type.Missing;
PictureBox pp = new PictureBox(); //新建一个PictureBox控件
object rng = Type.Missing;
string strInfo = "学生信息";
start = 0;
end = 0;
object lg = strInfo.Length;
wordDoc.Range(ref start, ref end).InsertBefore(strInfo); //插入文本
wordDoc.Range(ref start, ref lg).Font.Name = "Verdana"; //设置字体
wordDoc.Range(ref start, ref lg).Font.Size = 30; //设置字体大小
wordDoc.Range(ref start, ref lg).ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;//设置字体局中
start = strInfo.Length;
end = strInfo.Length;
wordDoc.Range(ref start, ref end).InsertParagraphAfter();//插入回车
object missingValue = Type.Missing;
object location = strInfo.Length;
Word.Range rng2 = wordDoc.Range(ref location, ref location);
int numberlunwen = 0;
int numbergrade = 0;
int numberhome = 0;
int numberstudy = 0;
int numberperson = 12;
//检索数据库看看 几人的信息是几行numberperson 发表的论文的数目记为:numberlunwen 查找个人的受奖励和惩罚的个数:numbergrade 查找家庭成员和社会关系个数numberhome 查找学习和工作记录numberstudy 根据这个记录生成最后的记录的总的个数
int totall = numbergrade + numberhome + numberlunwen + numberperson + numberstudy;
Word.Table table1 = wordDoc.Tables.Add(rng2, 28 + 13, 8, ref missingValue, ref missingValue); //建立一个table 这里应该又什么命令可以将每个格子里面的数据设置格式的但是在网上找的例子不太行
table1.Rows.HeightRule = Word.WdRowHeightRule.wdRowHeightAtLeast;
table1.Rows.Height = wordApp.CentimetersToPoints(float.Parse("1.2"));
table1.Range.Font.Size = 10;
table1.Range.Font.Name = "宋体";
//设置表格样式
table1.Borders.Item(Word.WdBorderType.wdBorderTop).LineStyle = Word.WdLineStyle.wdLineStyleSingle;
table1.Borders.Item(Word.WdBorderType.wdBorderTop).LineWidth = Word.WdLineWidth.wdLineWidth050pt;
table1.Borders.Item(Word.WdBorderType.wdBorderTop).Color = Word.WdColor.wdColorAutomatic;
table1.Borders.Item(Word.WdBorderType.wdBorderLeft).LineStyle = Word.WdLineStyle.wdLineStyleSingle;
table1.Borders.Item(Word.WdBorderType.wdBorderLeft).LineWidth = Word.WdLineWidth.wdLineWidth050pt;
table1.Borders.Item(Word.WdBorderType.wdBorderLeft).Color = Word.WdColor.wdColorAutomatic;
table1.Borders.Item(Word.WdBorderType.wdBorderHorizontal).LineStyle = Word.WdLineStyle.wdLineStyleSingle;
table1.Borders.Item(Word.WdBorderType.wdBorderVertical).LineStyle = Word.WdLineStyle.wdLineStyleSingle;
table1.Borders.Item(Word.WdBorderType.wdBorderHorizontal).LineWidth = Word.WdLineWidth.wdLineWidth050pt;
table1.Borders.Item(Word.WdBorderType.wdBorderHorizontal).Color = Word.WdColor.wdColorAutomatic;
table1.Borders.Item(Word.WdBorderType.wdBorderVertical).LineWidth = Word.WdLineWidth.wdLineWidth050pt;
table1.Borders.Item(Word.WdBorderType.wdBorderVertical).Color = Word.WdColor.wdColorAutomatic;
table1.Borders.Item(Word.WdBorderType.wdBorderBottom).LineStyle = Word.WdLineStyle.wdLineStyleSingle;
table1.Borders.Item(Word.WdBorderType.wdBorderBottom).LineWidth = Word.WdLineWidth.wdLineWidth050pt;
wordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;//设置中对其
//下面是用户的基本信息
//第1行显示
table1.Cell(1, 7).Merge(table1.Cell(4, 8));
table1.Cell(1, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 2).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 4).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 5).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 6).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(1, 1).Range.Text = "姓名";
table1.Cell(1, 2).Range.Text = "数据库姓名";
table1.Cell(1, 3).Range.Text = "性别";
table1.Cell(1, 4).Range.Text = "数据库性别";
table1.Cell(1, 5).Range.Text = "出生日期";
table1.Cell(1, 6).Range.Text = "数据库出生日期";
//第2行显示
table1.Cell(2, 2).Merge(table1.Cell(2, 4));
table1.Cell(2, 1).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(2, 2).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(2, 3).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(2, 4).VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
table1.Cell(2, 1).Range.Text = "证件号码";
table1.Cell(2, 2).Range.Text = "数据库证件号码";
table1.Cell(2, 3).Range.Text = "政治面貌";
table1.Cell(2, 4).Range.Text = "数据库政治面貌";