已阅读5页,还剩19页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Microsoft.Office.Interop.Word生产word的方法一、添加页眉01.using System; 02.using System.Collections.Generic; 03.using System.ComponentModel; 04.using System.Data; 05.using System.Linq; 06.using System.Text; 07.using Word = Microsoft.Office.Interop.Word; 08.using System.IO; 09.using System.Reflection; 10.using Microsoft.Office.Interop.Word; 11. 12. 13.namespace WordCreateDLL 14. 15. public class AddHeader 16. 17. public static void AddSimpleHeader(Application WordApp, string HeaderText) 18. 19. /添加页眉 20. WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; 21. WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; 22. WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); 23. WordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;/设置左对齐 24. WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; 25. 26. public static void AddSimpleHeader(Application WordApp, string HeaderText, WdParagraphAlignment wdAlign) 27. 28. /添加页眉 29. WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; 30. WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; 31. WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); 32. /WordApp.Selection.Font.Color = WdColor.wdColorDarkRed;/设置字体颜色 33. WordApp.Selection.ParagraphFormat.Alignment = wdAlign;/设置左对齐 34. WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; 35. 36. public static void AddSimpleHeader(Application WordApp, string HeaderText, WdParagraphAlignment wdAlign,WdColor fontcolor, float fontsize) 37. 38. /添加页眉 39. WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; 40. WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; 41. WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); 42. WordApp.Selection.Font.Color =fontcolor;/设置字体颜色 43. WordApp.Selection.Font.Size = fontsize;/设置字体大小 44. WordApp.Selection.ParagraphFormat.Alignment = wdAlign;/设置对齐方式 45. WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; 46. 47. 48. 49. 50. view plaincopy to clipboardprint?01.using 02.System; 03.using System.Collections.Generic; 04.using System.ComponentModel; 05.using System.Data; 06.using System.Linq; 07.using System.Text; 08.using Word = Microsoft.Office.Interop.Word; 09.using System.IO; 10.using System.Reflection; 11.using Microsoft.Office.Interop.Word; 12.namespace WordCreateDLL 13. public class AddHeader public static void 14.AddSimpleHeader(Application WordApp,string HeaderText) /添加页眉 15.WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; 16.WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; 17.WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); 18.WordApp.Selection.ParagraphFormat.Alignment = 19.WdParagraphAlignment.wdAlignParagraphLeft;/设置左对齐 20.WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; 21.public static void AddSimpleHeader(Application WordApp, string 22.HeaderText, WdParagraphAlignment wdAlign) /添加页眉 23.WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView; 24.WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader; 25.WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); 26./WordApp.Selection.Font.Color = WdColor.wdColorDarkRed;/设置字体颜色 27.WordApp.Selection.ParagraphFormat.Alignment = wdAlign;/设置左对齐 28.WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; 29.public static void AddSimpleHeader(Application WordApp, string 30.HeaderText, WdParagraphAlignment wdAlign,WdColor fontcolor,float 31.fontsize) /添加页眉 WordApp.ActiveWindow.View.Type = 32.WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView = 33.WdSeekView.wdSeekPrimaryHeader; 34.WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText); 35.WordApp.Selection.Font.Color =fontcolor;/设置字体颜色 36.WordApp.Selection.Font.Size = fontsize;/设置字体大小 37.WordApp.Selection.ParagraphFormat.Alignment = wdAlign;/设置对齐方式 38.WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; 39. usingSystem;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Linq;using System.Text;using Word = Microsoft.Office.Interop.Word;using System.IO;using System.Reflection;using Microsoft.Office.Interop.Word;namespace WordCreateDLL public class AddHeader public static voidAddSimpleHeader(Application WordApp,string HeaderText) /添加页眉WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText);WordApp.Selection.ParagraphFormat.Alignment =WdParagraphAlignment.wdAlignParagraphLeft;/设置左对齐WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; public static void AddSimpleHeader(Application WordApp, stringHeaderText, WdParagraphAlignment wdAlign) /添加页眉WordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText);/WordApp.Selection.Font.Color = WdColor.wdColorDarkRed;/设置字体颜色WordApp.Selection.ParagraphFormat.Alignment = wdAlign;/设置左对齐WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; public static void AddSimpleHeader(Application WordApp, stringHeaderText, WdParagraphAlignment wdAlign,WdColor fontcolor,floatfontsize) /添加页眉 WordApp.ActiveWindow.View.Type =WdViewType.wdOutlineView; WordApp.ActiveWindow.View.SeekView =WdSeekView.wdSeekPrimaryHeader;WordApp.ActiveWindow.ActivePane.Selection.InsertAfter(HeaderText);WordApp.Selection.Font.Color =fontcolor;/设置字体颜色WordApp.Selection.Font.Size = fontsize;/设置字体大小WordApp.Selection.ParagraphFormat.Alignment = wdAlign;/设置对齐方式WordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument; 二、插入图片01.using System; 02.using System.Collections.Generic; 03.using System.ComponentModel; 04.using System.Data; 05.using System.Linq; 06.using System.Text; 07.using Word = Microsoft.Office.Interop.Word; 08.using System.IO; 09.using System.Reflection; 10.using Microsoft.Office.Interop.Word; 11. 12.namespace WordCreateDLL 13. 14. public class AddPic 15. 16. public static void AddSimplePic(Document WordDoc, string FName, float Width, float Height, object An, WdWrapType wdWrapType) 17. 18. /插入图片 19. string FileName = FName; /图片所在路径 20. object LinkToFile = false ; 21. object SaveWithDocument = true ; 22. object Anchor = An; 23. WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor); 24. WordDoc.Application.ActiveDocument.InlineShapes1.Width = Width;/图片宽度 25. WordDoc.Application.ActiveDocument.InlineShapes1.Height = Height;/图片高度 26. /将图片设置为四周环绕型 27. Microsoft.Office.Interop.Word.Shape s = WordDoc.Application.ActiveDocument.InlineShapes1.ConvertToShape(); 28. s.WrapFormat.Type = wdWrapType; 29. 30. 31. 32. view plaincopy to clipboardprint?01.using 02.System; 03.using System.Collections.Generic; 04.using System.ComponentModel; 05.using System.Data; 06.using System.Linq; 07.using System.Text; 08.using Word = Microsoft.Office.Interop.Word; 09.using System.IO; 10.using System.Reflection; 11.using Microsoft.Office.Interop.Word; 12.namespace WordCreateDLL 13. public class AddPic public static void AddSimplePic(Document 14.WordDoc, string FName, float Width, float Height, object An, WdWrapType 15.wdWrapType) /插入图片 string FileName = FName;/图片所在路径 object 16.LinkToFile = false; object SaveWithDocument = true; object Anchor = An; 17.WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, 18.ref LinkToFile, ref SaveWithDocument, ref Anchor); 19.WordDoc.Application.ActiveDocument.InlineShapes1.Width = Width;/图片宽度 20.WordDoc.Application.ActiveDocument.InlineShapes1.Height = 21.Height;/图片高度 /将图片设置为四周环绕型 Microsoft.Office.Interop.Word.Shape s = 22.WordDoc.Application.ActiveDocument.InlineShapes1.ConvertToShape(); 23.s.WrapFormat.Type = wdWrapType; 24. usingSystem;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Linq;using System.Text;using Word = Microsoft.Office.Interop.Word;using System.IO;using System.Reflection;using Microsoft.Office.Interop.Word;namespace WordCreateDLL public class AddPic public static void AddSimplePic(DocumentWordDoc, string FName, float Width, float Height, object An, WdWrapTypewdWrapType) /插入图片 string FileName = FName;/图片所在路径 objectLinkToFile = false; object SaveWithDocument = true; object Anchor = An;WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName,ref LinkToFile, ref SaveWithDocument, ref Anchor);WordDoc.Application.ActiveDocument.InlineShapes1.Width = Width;/图片宽度WordDoc.Application.ActiveDocument.InlineShapes1.Height =Height;/图片高度 /将图片设置为四周环绕型 Microsoft.Office.Interop.Word.Shape s =WordDoc.Application.ActiveDocument.InlineShapes1.ConvertToShape();s.WrapFormat.Type = wdWrapType; 三、插入表格01.using System; 02.using System.Collections.Generic; 03.using System.ComponentModel; 04.using System.Data; 05.using System.Linq; 06.using System.Text; 07.using Word = Microsoft.Office.Interop.Word; 08.using System.IO; 09.using System.Reflection; 10.using Microsoft.Office.Interop.Word; 11. 12.namespace WordCreateDLL 13. 14. public class AddTable 15. 16. public static void AddSimpleTable(Application WordApp, Document WordDoc, int numrows, int numcolumns, WdLineStyle outStyle, WdLineStyle intStyle) 17. 18. Object Nothing = System.Reflection.Missing.Value; 19. /文档中创建表格 20. Microsoft.Office.Interop.Word.Table newTable = WordDoc.Tables.Add(WordApp.Selection.Range, numrows, numcolumns, ref Nothing, ref Nothing); 21. /设置表格样式 22. newTable.Borders.OutsideLineStyle = outStyle; 23. newTable.Borders.InsideLineStyle = intStyle; 24. newTable.Columns1.Width = 100f; 25. newTable.Columns2.Width = 220f; 26. newTable.Columns3.Width = 105f; 27. 28. /填充表格内容 29. newTable.Cell(1, 1).Range.Text = 产品详细信息表 ; 30. newTable.Cell(1, 1).Range.Bold = 2;/设置单元格中字体为粗体 31. /合并单元格 32. newTable.Cell(1, 1).Merge(newTable.Cell(1, 3); 33. WordApp.Selection.Cells.VerticalAlignment =WdCellVerticalAlignment.wdCellAlignVerticalCenter;/垂直居中 34. WordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;/水平居中 35. 36. /填充表格内容 37. newTable.Cell(2, 1).Range.Text = 产品基本信息 ; 38. newTable.Cell(2, 1).Range.Font.Color =WdColor.wdColorDarkBlue;/设置单元格内字体颜色 39. /合并单元格 40. newTable.Cell(2, 1).Merge(newTable.Cell(2, 3); 41. WordApp.Selection.Cells.VerticalAlignment =WdCellVerticalAlignment.wdCellAlignVerticalCenter; 42. 43. /填充表格内容 44. newTable.Cell(3, 1).Range.Text = 品牌名称: ; 45. newTable.Cell(3, 2).Range.Text = 品牌名称: ; 46. /纵向合并单元格 47. newTable.Cell(3, 3).Select();/选中一行 48. object moveUnit = WdUnits.wdLine; 49. object moveCount = 5; 50. object moveExtend = WdMovementType.wdExtend; 51. WordApp.Selection.MoveDown(ref moveUnit, ref moveCount, ref moveExtend); 52. WordApp.Selection.Cells.Merge(); 53. 54. 55. /插入图片 56. string FileName = C:1.jpg ; /图片所在路径 57. object Anchor = WordDoc.Application.Selection.Range; 58. float Width = 200f; /图片宽度 59. float Height = 200f; /图片高度 60. 61. /将图片设置为四周环绕型 62. WdWrapType wdWrapType = Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare; 63. AddPic.AddSimplePic(WordDoc, FileName, Width, Height, Anchor, wdWrapType); 64. 65. newTable.Cell(12, 1).Range.Text = 产品特殊属性 ; 66. newTable.Cell(12, 1).Merge(newTable.Cell(12, 3); 67. /在表格中增加行 68. WordDoc.Content.Tables1.Rows.Add(ref Nothing); 69. 70. 71. 72. 73. view plaincopy to clipboardprint?01.using 02.System; 03.using System.Collections.Generic; 04.using System.ComponentModel; 05.using System.Data; 06.using System.Linq; 07.using System.Text; 08.using Word = Microsoft.Office.Interop.Word; 09.using System.IO; 10.using System.Reflection; 11.using Microsoft.Office.Interop.Word; 12.namespace WordCreateDLL 13. public class AddTable public static void AddSimpleTable(Application 14.WordApp, Document WordDoc, int numrows, int numcolumns, WdLineStyle 15.outStyle, WdLineStyle intStyle) Object Nothing = 16.System.Reflection.Missing.Value; /文档中创建表格 17.Microsoft.Office.Interop.Word.Table newTable = 18.WordDoc.Tables.Add(WordApp.Selection.Range, numrows, numcolumns, ref 19.Nothing, ref Nothing); /设置表格样式 newTable.Borders.OutsideLineStyle = 20.outStyle; newTable.Borders.InsideLineStyle = intStyle; 21.newTable.Columns1.Width = 100f; newTable.Columns2.Width = 220f; 22.newTable.Columns3.Width = 105f; /填充表格内容 newTable.Cell(1, 23.1).Range.Text = 产品详细信息表; newTable.Cell(1, 1).Range.Bold = 24.2;/设置单元格中字体为粗体 /合并单元格 newTable.Cell(1, 1).Merge(newTable.Cell(1, 3); 25.WordApp.Selection.Cells.VerticalAlignment 26.=WdCellVerticalAlignment.wdCellAlignVerticalCenter;/垂直居中 27.WordApp.Selection.ParagraphFormat.Alignment = 28.WdParagraphAlignment.wdAlignParagraphCenter;/水平居中 /填充表格内容 29.newTable.Cell(2, 1).Range.Text = 产品基本信息; newTable.Cell(2, 30.1).Range.Font.Color =WdColor.wdColorDarkBlue;/设置单元格内字体颜色 /合并单元格 31.newTable.Cell(2, 1).Merge(newTable.Cell(2, 3); 32.WordApp.Selection.Cells.VerticalAlignment 33.=WdCellVerticalAlignment.wdCellAlignVerticalCenter; /填充表格内容 34.newTable.Cell(3, 1).Range.Text = 品牌名称:; newTable.Cell(3, 35.2).Range.Text = 品牌名称:; /纵向合并单元格 newTable.Cell(3, 3).Select();/选中一行 36.object moveUnit = WdUnits.wdLine; object moveCount = 5; object 37.moveExtend = WdMovementType.wdExtend; WordApp.Selection.MoveDown(ref 38.moveUnit, ref moveCount, ref moveExtend); 39.WordApp.Selection.Cells.Merge(); /插入图片 string FileName = 40.C:1.jpg;/图片所在路径 object Anchor = 41.WordDoc.Application.Selection.Range; float Width = 200f;/图片宽度 float 42.Height = 200f;/图片高度 /将图片设置为四周环绕型 WdWrapType wdWrapType = 43.Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare; 44.AddPic.AddSimplePic(WordDoc, FileName, Width, Height, Anchor, 45.wdWrapType); newTable.Cell(12, 1).Range.Text = 产品特殊属性; 46.newTable.Cell(12, 1).Merge(newTable.Cell(12, 3); /在表格中增加行 47.WordDoc.Content.Tables1.Rows.Add(ref Nothing); 48. usingSystem;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Linq;using System.Text;using Word = Microsoft.Office.Interop.Word;using System.IO;using System.Reflection;using Microsoft.Office.Interop.Word;namespace WordCreateDLL public class AddTable public static void AddSimpleTable(ApplicationWordApp, Document WordDoc, int numrows, int numcolumns, WdLineStyleoutStyle, WdLineStyle intStyle) Object Nothing =System.Reflection.Missing.Value; /文档中创建表格Microsoft.Office.Interop.Word.Table newTable =WordDoc.Tables.Add(WordApp.Selection.Range, numrows, numcolumns, refNothing, ref Nothing); /设置表格样式 newTable.Borders.OutsideLineStyle =outStyle; newTable.Borders.InsideLineStyle = intStyle;newTable.Columns1.Width = 100f; newTable.Columns2.Width = 220f;newTable.Columns3.Width = 105f; /填充表格内容 newTable.Cell(1,1).Range.Text = 产品详细信息表; newTable.Cell(1, 1).Range.Bold =2;/设置单元格中字体为粗体 /合并单元格 newTable.Cell(1, 1).Merge(newTable.Cell(1, 3);WordApp.Selection.Cells.VerticalAlignment=WdCellVerticalAlignment.wdCellAlignVerticalCenter;/垂直居中WordApp.Selection.ParagraphFormat.Alignment =WdParagraphAlignment.wdAlignParagraphCenter;/水平居中 /填充表格内容newTable.Cell(2, 1).Range.Text = 产品基本信息; newTable.Cell(2,1).Range.Font.Color =WdColor.wdColorDarkBlue;/设置单元格内字体颜色 /合并单元格newTable.Cell(2, 1).Merge(newTable.Cell(2, 3);WordApp.Selection.Cells.VerticalAlignment=WdCellVerticalAlignment.wdCellAlignVerticalCenter; /填充表格内容newTable.Cell(3, 1).Range.Text = 品牌名称:; newTable.Cell(3,2).Range.Text =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年劳资专管员培训考试题库及答案
- 2025办公室工作年终总结范文3篇
- 2025年中远海运国际分公司招聘面试题与答题思路解析
- 2025商业房地产买卖合同
- 2025年下半年吉林省长春市公用事业信息中心工作人员招聘2人易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年台州市民政局下属事业单位招考易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年南通市通州区招考内河交通安全管理辅助执法人员易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年南昌市青山湖区专职招商人员招考(10人)易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年南京军区房地产管理局南平分局招考易考易错模拟试题(共500题)试卷后附参考答案
- 2025年下半年北京市怀柔区面向社会招聘事业单位工作人员笔试易考易错模拟试题(共500题)试卷后附参考答案
- (高清版)DB34∕T 1267-2025 造林技术规程
- 大学生职业生涯规划书(教育专业)
- 《低钠血症的中国专家共识(2023)》解读
- 乳房疾病预防与保养
- 五粮液国庆茅台活动方案
- 日语入门考试试题及答案
- T/CGCC 14-2018无形资产价值评价体系
- T/CBMCA 022-2021陶瓷岩板加工规范
- 三级医院评审标准实施细则(2023 年版)
- 股东退股注销协议书
- 《继电器原理及其应用》课件
评论
0/150
提交评论