这里将介绍C#中using word相关用法及代码示例,笔者搜集了Microsoft.Office.Interop.Word生产word的一些方法,希望对大家有所帮助。
在C#中using word的命名空间,大多是使用Microsoft.Office.Interop.Word来生成word的办法。以下是一些C#中using word的不同用法
将现有的C#中using word劳动成果放在这儿。有时间在加以完善!
一、增加页眉
- viewplaincopytoclipboardprint?
- usingSystem;
- usingSystem.Collections.Generic;
- usingSystem.ComponentModel;
- usingSystem.Data;
- usingSystem.Linq;
- usingSystem.Text;
- usingWord=Microsoft.Office.Interop.Word;
- usingSystem.IO;
- usingSystem.Reflection;
- usingMicrosoft.Office.Interop.Word;
- namespaceWordCreateDLL
- {
- publicclassAddHeader
- {
- publicstaticvoidAddSimpleHeader(ApplicationWordApp,stringHeaderText)
- {
- //增加页眉
- 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;
- }
- publicstaticvoidAddSimpleHeader(ApplicationWordApp,stringHeaderText,WdParagraphAlignmentwdAlign)
- {
- //增加页眉
- 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;
- }
- publicstaticvoidAddSimpleHeader(ApplicationWordApp,stringHeaderText,WdParagraphAlignmentwdAlign,WdColorfontcolor,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;
- }
- }
- }
- usingSystem;
- usingSystem.Collections.Generic;
- usingSystem.ComponentModel;
- usingSystem.Data;
- usingSystem.Linq;
- usingSystem.Text;
- usingWord=Microsoft.Office.Interop.Word;
- usingSystem.IO;
- usingSystem.Reflection;
- usingMicrosoft.Office.Interop.Word;
- namespaceWordCreateDLL
- {
- publicclassAddHeader
- {
- publicstaticvoidAddSimpleHeader(ApplicationWordApp,stringHeaderText)
- {
- //增加页眉
- 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;
- }
- publicstaticvoidAddSimpleHeader(ApplicationWordApp,stringHeaderText,WdParagraphAlignmentwdAlign)
- {
- //增加页眉
- 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;
- }
- publicstaticvoidAddSimpleHeader(ApplicationWordApp,stringHeaderText,WdParagraphAlignmentwdAlign,WdColorfontcolor,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;
- }
- }
- }
二、刺进图片
- viewplaincopytoclipboardprint?
- usingSystem;
- usingSystem.Collections.Generic;
- usingSystem.ComponentModel;
- usingSystem.Data;
- usingSystem.Linq;
- usingSystem.Text;
- usingWord=Microsoft.Office.Interop.Word;
- usingSystem.IO;
- usingSystem.Reflection;
- usingMicrosoft.Office.Interop.Word;
- namespaceWordCreateDLL
- {
- publicclassAddPic
- {
- publicstaticvoidAddSimplePic(DocumentWordDoc,stringFName,floatWidth,floatHeight,objectAn,WdWrapTypewdWrapType)
- {
- //刺进图片
- stringFileName=@FName;//图片地点途径
- objectLinkToFile=false;
- objectSaveWithDocument=true;
- objectAnchor=An;
- WordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName,refLinkToFile,refSaveWithDocument,refAnchor);
- WordDoc.Application.ActiveDocument.InlineShapes[1].Width=Width;//图片宽度
- WordDoc.Application.ActiveDocument.InlineShapes[1].Height=Height;//图片高度
- //将图片设置为四周盘绕型
- Microsoft.Office.Interop.Word.Shapes=WordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();
- s.WrapFormat.Type=wdWrapType;
- }
- }
- }
- usingSystem;
- usingSystem.Collections.Generic;
- usingSystem.ComponentModel;
- usingSystem.Data;
- usingSystem.Linq;
- usingSystem.Text;
- usingWord=Microsoft.Office.Interop.Word;
- usingSystem.IO;
- usingSystem.Reflection;
- usingMicrosoft.Office.Interop.Word;
- namespaceWordCreateDLL
- {
- publicclassAddPic
- {
- publicstaticvoidAddSimplePic(DocumentWordDoc,stringFName,floatWidth,floatHeight,objectAn,WdWrapTypewdWrapType)
- {
- //刺进图片
- stringFileName=@FName;
转载请说明出处
知优网 » C#中using word相关用法及代码示例(c#中using的用法)
知优网 » C#中using word相关用法及代码示例(c#中using的用法)