自动生成SQL Server数据库的Word文档格式的数据字典.docx_第1页
自动生成SQL Server数据库的Word文档格式的数据字典.docx_第2页
自动生成SQL Server数据库的Word文档格式的数据字典.docx_第3页
自动生成SQL Server数据库的Word文档格式的数据字典.docx_第4页
自动生成SQL Server数据库的Word文档格式的数据字典.docx_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/添加word引用using Word = Microsoft.Office.Interop.Word;using System.Reflection;namespace SQLServerToWord.Includepublic class OperateWordprivate void CreateWordTable(int index,string tableName,DataView dv,Word._Document oDoc,object oMissing,object oEndOfDoc,Word._Application oWord)/创建表标题Word.Paragraph oPara3;object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;oPara3 = oDoc.Content.Paragraphs.Add(ref oRng);oPara3.Range.Text = index.ToString() + . + tableName + 表;oPara3.Range.Font.Bold = 0;oPara3.Format.SpaceAfter = 6;oPara3.Range.InsertParagraphAfter();/创建表格Word.Table oTable;Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;oTable = oDoc.Tables.Add(wrdRng,dv.Count + 1,5,ref oMissing,ref oMissing);oTable.Range.ParagraphFormat.SpaceAfter = 6;/创建表的表头oTable.Cell(1,1).Range.Text = 字段名称;oTable.Cell(1,2).Range.Text = 数据类型;oTable.Cell(1,3).Range.Text = 是否为空;oTable.Cell(1,4).Range.Text = 键引用;oTable.Cell(1,5).Range.Text = 说明;int i = 2;foreach(DataRowView row in dv) /添加列名称oTable.Cell(i,1).Range.Text = rowcolumn_name.ToString();/添加列的数据类型if(rowdata_type.ToString() != text & rowcharacter_maximum_length.ToString() != )oTable.Cell(i,2).Range.Text = rowdata_type.ToString()+ ( + rowcharacter_maximum_length.ToString() + );elseoTable.Cell(i,2).Range.Text = rowdata_type.ToString();/添加列的非空字段标识oTable.Cell(i,3).Range.Text = rowis_nullable.ToString();/添加键引用标识if(rowcolumn_name.ToString() = ID)oTable.Cell(i,4).Range.Text = PK;if(rowcolumn_name.ToString() != ID & rowcolumn_name.ToString().EndsWith(ID)oTable.Cell(i,4).Range.Text = FK;i+;/表头字体加粗oTable.Rows1.Range.Font.Bold = 1;oTable.Rows1.Range.Font.Italic = 1;/表格宽度适合文本oTable.AllowAutoFit = true;oTable.ApplyStyleHeadingRows = true;/设置表头的背景颜色oTable.Rows1.Range.Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorSkyBlue;/设置边框为1oTable.Borders.Enable = 1;public void CreateWord(DataView dvTable,DataView dvColumn)object oMissing = System.Reflection.Missing.Value;object oEndOfDoc = ; /* endofdoc is a predefined bookmark */创建一个word文档Word._Application oWord;Word._Document oDoc;oWord = new Word.Application();oWord.Visible = true;oDoc = oWord.Documents.Add(ref oMissing,ref oMissing,ref oMissing,ref oMissing);/创建表格int i = 1;foreach(DataRowView row in dvTable) /创建一个表格CreateWordTable(i,rowtable_name.ToString(),GetColumnByTable(dvColumn,rowtable_name.ToString(),oDoc,oMissing,oEndOfDoc,oWord);i+;private DataView GetColumnByTable(DataView dvColumn,string tableName)dvColumn.Sort = table_name,ordinal_position;dvColumn.RowFilter = table_name = + tableName + ;return dvColumn;public partial class ConvertSQLTableToWord:Formpublic ConvertSQLTableToWord()InitializeComponent();private void btnConvert_Click(object sender,EventArgs e)OperateWord word = new OperateWord();word.CreateWord(GetTables(),GetColumns();private SqlConnectionStringBuilder CreateConnectionString()SqlConnectionStringBuilder csbuilder = new SqlConnectionStringBuilder();csbuilder.DataSource = cbServer.Text.Trim();csbuilder.UserID = tbUserID.Text.Trim();csbuilder.Password = tbPwd.Text.Trim();csbuilder.InitialCatalog = cbDatabase.Text.Trim();return (csbuilder);private DataView GetTables()SqlConnection sqlCon = new SqlConnection(CreateConnectionString().ConnectionString);sqlCon.Open();DataTable dt = sqlCon.GetSchema(Tables);dt.DefaultView.Sort = table_name;sqlCon.Close();return dt.DefaultView;private DataView GetColumns

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论