资源描述:
《自动生成SQL Server数据库的Word文档格式的数据字典》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、///添加word引用usingWord=Microsoft.Office.Interop.Word;usingSystem.Reflection;namespaceSQLServerToWord.Include{ publicclassOperateWord { privatevoidCreateWordTable(intindex,stringtableName,DataViewdv, Word._DocumentoDoc,objectoMissing,objectoEndOfDoc, Word._ApplicationoWord) { ///创建表标题 W
2、ord.ParagraphoPara3; objectoRng=oDoc.Bookmarks.get_Item(refoEndOfDoc).Range; oPara3=oDoc.Content.Paragraphs.Add(refoRng); oPara3.Range.Text=index.ToString()+". "+tableName+"表"; oPara3.Range.Font.Bold=0; oPara3.Format.SpaceAfter=6; oPara3.Range.InsertParagraphAfter(); ///创建表格 Wo
3、rd.TableoTable; Word.RangewrdRng=oDoc.Bookmarks.get_Item(refoEndOfDoc).Range; oTable=oDoc.Tables.Add(wrdRng,dv.Count+1,5,refoMissing,refoMissing); oTable.Range.ParagraphFormat.SpaceAfter=6; ///创建表的表头 oTable.Cell(1,1).Range.Text="字段名称"; oTable.Cell(1,2).Range.Text="数据类型"; oTable.C
4、ell(1,3).Range.Text="是否为空"; oTable.Cell(1,4).Range.Text="键引用"; oTable.Cell(1,5).Range.Text="说明"; inti=2; foreach(DataRowViewrowindv) { ///添加列名称 oTable.Cell(i,1).Range.Text=row["column_name"].ToString(); ///添加列的数据类型 if(row["data_type"].ToString()!="text"&&row["character_maxi
5、mum_length"].ToString()!="") { oTable.Cell(i,2).Range.Text=row["data_type"].ToString() +"("+row["character_maximum_length"].ToString()+")"; } else { oTable.Cell(i,2).Range.Text=row["data_type"].ToString(); } ///添加列的非空字段标识 oTable.Cell(i,3).Range.Text=row["is_nu
6、llable"].ToString(); ///添加键引用标识 if(row["column_name"].ToString()=="ID") { oTable.Cell(i,4).Range.Text="PK"; } if(row["column_name"].ToString()!="ID"&&row["column_name"].ToString().EndsWith("ID")) { oTable.Cell(i,4).Range.Text="FK"; } i++; } ///表头字体加粗 oTabl
7、e.Rows[1].Range.Font.Bold=1; oTable.Rows[1].Range.Font.Italic=1; ///表格宽度适合文本 oTable.AllowAutoFit=true; oTable.ApplyStyleHeadingRows=true; ///设置表头的背景颜色 oTable.Rows[1].Range.Shading.BackgroundPatternColor=Microsoft.Office.Inte