




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/添加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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 江苏省苏州2024-2025学年九年级(上)物理第一次月考试卷(含答案)
- 抗菌药物的分级管理
- 抗生素使用常见问题课件
- 2025-2026统编版八年级上册第二单元测试题(含答案)
- 最难的育儿题目及答案
- 江西小学教资题库及答案
- 高中几何经典题目及答案
- 扑火安全教育培训报道课件
- 2025年海底捞文员考试题及答案
- 河南二建考试试题及答案
- 服装厂质检知识培训内容课件
- 2025年教师资格考试趋势分析与模拟试题洞察未来方向(含答案)
- 2025浙江省旅游投资集团人才招聘17人(第四批)考试模拟试题及答案解析
- 2025年潍坊市中考物理真题卷(含答案)
- 酒管专业导论考试题及答案
- 2025外研社小学英语四年级上册单词表(带音标)
- 2025至2030中国体育赛事行业市场发展分析及发展前景与投资报告
- 上消化道出血药物指导
- 重点金融政策解读
- 工贸行业安全管理和企业现场常见隐患排查解读(1)精
- 2025年注册核安全工程师执业资格考试(核安全专业实务·核技术)历年参考题库含答案详解(5套)
评论
0/150
提交评论