word排版源代码
- 格式:doc
- 大小:17.00 KB
- 文档页数:2
word中使用宏命令速排版的方法一、首先录制宏命令1、打开一个WORD文档,文档中如果有文字,可使下面的过程看到效果。
2、执行录制宏命令:选择菜单\工具\宏\录制宏命令,在打开的对话框中,填上:宏名框中填上表示该宏命令的作用,例如:去掉多余的空格,去掉多余的空行,去掉多余的手工换行符,去掉多余的段落标记符,排版字体为宋体字号为四号颜色为黑色等等。
点对话框中的确定按钮。
3、全选所有文字:按CTRL+A, 或者按下鼠标左键不松手,从文件首行拖到最后一行,或者选择:菜单\编辑\全选。
4、执行排版:去掉全部多余的空格:选择菜单\编辑\替换\在查找框中按一个空格,在替换框中不加任何符号,点全部替换按钮两次。
去掉多余的手工换行符:选择菜单\编辑\替换\在查找框中填上手工换行符,方法是按CTRL+6,再字母L,或者点按钮高级选项,展开后,点特殊字符按钮,在其中点手动换行符.在替换框中填上段落标记,方法是按CTRL+6,再按字母P,或者点按钮高级选项,展开后,点特殊字符按钮,在其中点段落标记.再按确定按钮两次.去掉多余的段落标记:选择菜单\编辑\替换\在查找框中填上两个段落标记,方法是按CTRL+6,再字母P,连续两次,出现^P^P,,或者点按钮高级选项,展开后,点特殊字符按钮,在其中点段落标记两次.在替换框中填上段落标记,方法是按CTRL+6,再按字母P,或者点按钮高级选项,展开后,点特殊字符按钮,在其中点段落标记.再按确定按钮两次.更换字体:在快捷菜单栏中,点字体对话框,例如:宋体.更换字号:在快捷菜单栏中,点字号对话框,例如;四号字.更换字的颜色:在快捷菜单栏中,点字体颜色,在打开的颜色选择对话框中,点选合适的颜色,也可用菜单\格式\字体,在对话框中,把所有的这些项,全部一次更换好.更换段落间距等:打开菜单\格式\段落\在对话框中,将常规、缩进、间距设置好,再按确定,一般情况如下图设置。
特别要注意,在以上更换过程中,由于是全部替换,所以文档是全选状态,文字反显。
Word中的插入和编辑源代码技巧Word是一款功能强大的文字处理软件,不仅可以用于编写文档、制作报告,还可以进行源代码的插入和编辑。
在本文中,我将分享一些在Word中插入和编辑源代码的技巧,帮助你更高效地进行代码编写和文档编辑。
首先,让我们来看一下如何插入源代码。
在Word中,你可以通过多种方式将源代码插入到文档中。
其中一种常用的方法是使用“插入对象”功能。
你可以在Word的菜单栏中找到“插入”选项,然后选择“对象”。
在弹出的对话框中,选择“打开”按钮,浏览并选择你想要插入的源代码文件。
点击“确定”后,源代码将会被插入到文档中。
除了使用“插入对象”功能,你还可以使用“粘贴”功能将源代码从其他编辑器中粘贴到Word中。
首先,将源代码复制到剪贴板中,然后在Word中选择你想要插入代码的位置,点击右键,选择“粘贴”选项。
在弹出的菜单中,选择“保留源格式”或“合并格式”,这样源代码的格式将会得到保留。
一旦源代码被插入到Word中,你可能需要对其进行编辑和格式化。
Word提供了一些实用的工具和功能,帮助你更好地编辑和管理源代码。
其中一个常用的功能是“自动更正”功能。
在Word的菜单栏中,选择“文件”选项,然后点击“选项”。
在弹出的对话框中,选择“校对”选项卡,然后点击“自动更正选项”按钮。
在“自动更正”对话框中,你可以添加自定义的代码片段和替换规则,让Word自动对源代码进行格式化和编辑。
另一个有用的功能是“代码段落”格式。
在Word中,你可以将源代码块设置为“代码段落”格式,这样可以使代码更易于阅读和理解。
要设置代码段落格式,首先选中你想要设置格式的代码块,然后在Word的菜单栏中选择“开始”选项卡,点击“样式”下拉菜单中的“代码段落”选项。
代码块将会被自动格式化为代码段落样式,使其在文档中更加突出和易于辨认。
此外,Word还提供了一些其他的编辑工具,帮助你更好地管理和修改源代码。
例如,你可以使用“查找和替换”功能来快速查找和替换代码中的特定内容。
c#写word⽂档基础操作(⾃⼰控制样式)下⾯⼀个函数,建⽴⼀个Word ⽂档,添加页眉、页脚,在内容中两个不同字体的Hellopublic void myFunction(){Word.ApplicationClass oWordApp = new Word.ApplicationClass();//建⽴Word 对象,启动word程序object missing = System.Reflection.Missing.Value;object oTemplate = System.Windows.Forms.Application.StartupPath+"\\mytemplate.dot";Word.Document oWordDoc = oWordApp.Documents.Add( ref oTemplate,ref missing,ref missing, ref missing);//新建word⽂档oWordApp.Visible = true;//设置Word程序可见,如果为false 那么word 不可见//页⾯设置oWordDoc.PageSetup.TopMargin = oWordApp.CentimetersToPoints(2.5f); //上oWordDoc.PageSetup.BottomMargin = oWordApp.CentimetersToPoints(2f);//下oWordDoc.PageSetup.LeftMargin=oWordApp.CentimetersToPoints(2.2f);//左oWordDoc.PageSetup.RightMargin=oWordApp.CentimetersToPoints(2.2f);//右//添加页眉oWordDoc.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader; //激活页眉的编辑oWordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; //设置对齐⽅式string headtext1 ="Head Text"; ="华⽂新魏"; //设置字体oWordApp.Selection.Font.Size =10.5f;oWordApp.Selection.Font.UnderlineColor = Word.WdColor.wdColorAutomatic;oWordApp.Selection.Font.Underline = Word.WdUnderline.wdUnderlineSingle; //添加下划线oWordApp.Selection.TypeText(headtext1);oWordApp.Selection.Font.Underline = Word.WdUnderline.wdUnderlineNone;//添加页脚string foottext1 ="Foot Text";oWordDoc.ActiveWindow.ActivePane.View.SeekView =Word.WdSeekView.wdSeekCurrentPageFooter; //激活页脚的编辑oWordApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphCenter; ="仿宋_GB2312";oWordApp.Selection.Font.Size =8;oWordApp.Selection.TypeText(foottext1);//添加正⽂oWordDoc.ActiveWindow.ActivePane.View.SeekView =Word.WdSeekView.wdSeekMainDocument;//激活页⾯内容的编辑 ="宋体";oWordApp.Selection.Font.Size =10.5f;oWordApp.Selection.Font.Scaling = 200;oWordApp.Selection.TypeText("Hello");oWordApp.Selection.TypeParagraph();//另起⼀段 ="⿊体";oWordApp.Selection.Font.Size =10.5f;oWordApp.Selection.Font.Scaling = 100;oWordApp.Selection.TypeText("Hello");oWordApp.Selection.TypeParagraph();//另起⼀段string strfilename = System.Windows.Forms.Application.StartupPath+"\\myfirst.doc";object filename = strfilename ;//保存⽂档为word2000格式oWordDoc.SaveAs2000(ref filename,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing,ref missing);//保存⽂档为word2003格式//oWordDoc.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing,// ref missing, ref missing, ref missing, ref missing, ref missing,// ref missing, ref missing, ref missing, ref missing, ref missing,// ref missing) ;//以下关闭Word程序object nochanges = Word.WdSaveOptions.wdDoNotSaveChanges;if(oWordApp.Documents!= null){IEnumerator ie = oWordApp.Documents.GetEnumerator();while( ie.MoveNext()){Word.Document closedoc = (Word.Document)ie.Current;closedoc.Close(ref nochanges,ref missing,ref missing);}}oWordApp.Quit(ref nochanges, ref missing, ref missing);}。
word宏代码集锦Word宏代码集锦Word宏代码集锦一、修改word格式:1、'智能清除选区软回车(换行符)2、'清除选区多余空段3、'合并选区中“,”结束的多余分段4、'清除选区单字节空格5、'清除选区单字节空格6、'清除选区1字空格7、'清除选区段首2字空格8、'清除选区Tab9、'增加选区空格10、'选区段首缩进0字11、'选区段首缩进:2字12、'选区段首缩进转空格—已完美13、'选区段后间距1行14、'选区段后间距1行15、'选区段后间距1行16、'清除选区图片17、'选区硬回车转软回车18、'清除选区软回车19'合并选区段落20、'选区空格转硬回车21、'选区标点半角转全角22、'选区标点全角转半角23、'选区中文句号转半角24、’把文档第一段设置为标题1的格式25、选中的文本横向居中26、缩小字距27、增大字距28、缩小行距29、增大行距30、等高变宽31、等高变窄32、字表间距33、纵向16开34、插入页码35、小写金额转大写金额二、其它1.调整图片大小2.转字体3.转文件格式4、文件加密5、字符替换6、替换引号7、打印为PDF格式文件8、朗读文本9.文献标号上标化10.箭头上方加文字11添加参考文献格式一,参考文献在文档末尾以1. 2. 3.格式排列12.添加参考文献格式二,参考文献在文档末尾以[1] [2] [3]格式排列,修改自格式一的代码13.返回正文14.再次引用已有参考文献15.查找被删参考文献遗留引用,16、统计修订的字数17、快速提取脚注内容18、从任意页面编排页码19、批量实现缩放打印20、对文档内容进行顺序排列21、替换Word文档插图的超链接22、为文档的每页添加固定内容23、批量实现图片的等比例缩一、修改word格式:1、' 智能清除选区软回车(换行符)Sub 智能清除选区软回车()With Selection.Find.Text = "?^l".Replacement.Text = "^&^p".Forward = True.Wrap = wdFindContinue.Format = False.MatchCase = False.MatchWholeWord = False.MatchByte = False.MatchAllWordForms = False.MatchSoundsLike = False.MatchWildcards = TrueEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^1^l".Replacement.Text = "^&^p"End WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^l".Replacement.Text = ""End WithSelection.Find.Execute Replace:=wdReplaceAllEnd Sub2、' 清除选区多余空段Sub 清除选区多余空段()With Selection.Find.Text = "^p^p".Replacement.Text = "^p".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^p^p^p".Replacement.Text = "^p".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^p^p^p".Replacement.Text = "^p".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^p^p".Replacement.Text = "^p".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^p^p".Replacement.Text = "^p".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^p^p^p".Replacement.Text = "^p".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^p ".Replacement.Text = "^p".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^p^p".Replacement.Text = "^p".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^p^p".Replacement.Text = "^p".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAll End Sub3、' 合并选区中“,”结束的多余分段Sub 合并选区多余分段()With Selection.Find.Text = ",^p".Replacement.Text = ",".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "、^p".Replacement.Text = "、".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAll End Sub4、' 清除选区单字节空格Sub 清除选区单字节空格()With Selection.Find.Text = " ".Replacement.Text = "".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAll End Sub5、' 清除选区单字节空格Sub 清除选区2单字节空格()With Selection.Find.Text = " ".Replacement.Text = "".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAll End Sub6、' 清除选区1字空格Sub 清除选区1字空格()With Selection.Find.Text = " ".Replacement.Text = "".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllEnd Sub7、' 清除选区段首2字空格Sub 清除选区段首2字空格()With Selection.Find.Text = " ".Replacement.Text = "".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllEnd Sub8、' 清除选区TabSub 清除选区Tab()With Selection.Find.Text = vbTab.Replacement.Text = "".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAll End Sub9、' 增加选区空格Sub 增加选区空格()With Selection.Find.Text = " ".Replacement.Text = " ".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAll End Sub10、' 选区段首缩进0字Sub 选区段首无缩进()With Selection.Find.Text = " ".Replacement.Text = "".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.ParagraphFormat.LeftIndent = CentimetersT oPoints(0) '左缩进0字符.RightIndent = CentimetersT oPoints(0) '右缩进0字符.FirstLineIndent = CentimetersToPoints(0) '首行缩进点0公分.CharacterUnitLeftIndent = 0 '左缩进单位0字符.CharacterUnitRightIndent = 0 '右缩进单位0字符.CharacterUnitFirstLineIndent = 0End WithWith Selection.ParagraphFormat.LeftIndent = CentimetersT oPoints(0) '左缩进1字符.RightIndent = CentimetersT oPoints(0) '右缩进2字符.FirstLineIndent = CentimetersToPoints(0) '首行缩进点0.35公分.CharacterUnitLeftIndent = 0 '左缩进单位0字符.CharacterUnitRightIndent = 0 '右缩进单位0字符.CharacterUnitFirstLineIndent = 0End WithEnd Sub11、' 选区段首缩进:2字Sub 选区段首缩进2字()With Selection.ParagraphFormat.LeftIndent = CentimetersT oPoints(0) '左缩进1字符.RightIndent = CentimetersT oPoints(0) '右缩进2字符.FirstLineIndent = CentimetersToPoints(0.35) '首行缩进点单位公分.CharacterUnitLeftIndent = 0 '左缩进单位0字符.CharacterUnitRightIndent = 0 '右缩进单位0字符.CharacterUnitFirstLineIndent = 2End WithEnd Sub12、' 选区段首缩进转空格—已完美Sub 选区段首缩进转空格()Selection.InsertParagraphBeforeCall 选区段首无缩进With Selection.Find.Text = "^p".Replacement.Text = "^p ".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllSelection.DeleteWith Selection.Find.Text = " ^p".Replacement.Text = "".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllEnd Sub13、' 选区段后间距1行Sub 选区段后间距1行()Selection.ParagraphFormat.FirstLineIndent = CentimetersToPoints(0)Selection.ParagraphFormat.LineUnitAfter = 1End Sub14、' 选区段后间距1行Sub 选区段前段后间距半行()Selection.ParagraphFormat.FirstLineIndent = CentimetersToPoints(0)Selection.ParagraphFormat.LineUnitBefore = 0.5Selection.ParagraphFormat.LineUnitAfter = 0.5End Sub15、' 选区段后间距1行Sub 选区段前段后无间距()Selection.ParagraphFormat.FirstLineIndent = CentimetersToPoints(0)Selection.ParagraphFormat.LineUnitBefore = 0Selection.ParagraphFormat.LineUnitAfter = 0End Sub16、' 清除选区图片Sub 清除选区图片()With Selection.Find.Text = "^1".Replacement.Text = "".MatchWildcards = TrueEnd WithSelection.Find.Execute Replace:=wdReplaceAllEnd Sub17、' 选区硬回车转软回车Sub 选区硬回车转软回车()With Selection.Find.Text = "^p".Replacement.Text = "^l".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAll End Sub18、' 清除选区软回车Sub 清除选区软回车()' With Selection.Find.Text = "^l".Replacement.Text = "".MatchWildcards = TrueEnd WithSelection.Find.Execute Replace:=wdReplaceAll End Sub19'合并选区段落Sub 合并选区段落()With Selection.Find.Text = " ".Replacement.Text = "".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^p".Replacement.Text = "^l".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "^l".Replacement.Text = "".MatchWildcards = TrueEnd WithSelection.Find.Execute Replace:=wdReplaceAll Selection.Paragraphs.Add '添加段落符号End Sub20、' 选区空格转硬回车Sub 选区空格转硬回车()With Selection.Find.Text = " ".Replacement.Text = "^p".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllEnd Sub21、' 选区标点半角转全角Sub 选区标点半角转全角()With Selection.Find.Text = ",".Replacement.Text = ",".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = ";".Replacement.Text = ";".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = ":".Replacement.Text = ":".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAll With Selection.Find.Text = "?".Replacement.Text = "?".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "!".Replacement.Text = "!".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = "......".Repl acement.Text = "……".MatchWildcards = FalseEnd WithSelection.Find.Execute Replace:=wdReplaceAllWith Selection.Find.Text = ".".Replacement.Text = "。
Word 中的域代码列表Word for Office 365 Word for Office 365 forMac Word 2019 Word 2019 for Mac 更多...注意:我们希望能够尽快以你的语言为你提供最新的帮助内容。
本页面是自动翻译的,可能包含语法错误或不准确之处。
我们的目的是使此内容能对你有所帮助。
可以在本页面底部告诉我们此信息是否对你有帮助吗?请在此处查看本文的英文版本以便参考。
注意:有关插入和编辑域代码、使用开关、设置和更改属性、显示结果与域代码、锁定域和其他常见任务的详细信息, 请参阅在 Word 中插入、编辑和查看域。
在 Word 中插入、编辑和查看域域代码可用作文档中可能会更改的数据的占位符, 并且你可以使用它们来自动处理文档的某些方面。
当您使用 Word 功能 (如页码或目录) 时, 将插入域代码, 但是您可以为其他任务手动插入域代码, 例如执行计算或填充数据源中的文档内容。
这些步骤适用于在 Word 中插入任何域代码。
有关包含每个域的详细信息的所有域代码的列表, 请参阅Word 中的域代码列表。
插入域1.在要插入域的位置单击。
提示:如果你知道要插入的字段的域代码, 则可以直接在文档中键入它, 但不能键入方括号字符。
按 Ctrl + F9, 然后在括号中键入代码。
2.单击“插入”>“文档部件”>“域”。
3.在“域名”列表中,选择域名。
提示:您可以通过单击 "类别" 列表中的向下箭头筛选列表。
4.在 "字段属性" 下, 选择所需的任何属性或选项, 然后单击"确定"。
注意:•若要在 "字段" 框中查看特定字段的代码, 请单击 "域代码"。
对于某些字段, 默认情况下会单击此按钮。
•若要在另一个域中嵌套某个域,请先插入外部(容器)域(上面的步骤 1 - 4)。
C#操作Word的超详细总结本⽂中⽤C#来操作Word,包括:创建Word;插⼊⽂字,选择⽂字,编辑⽂字的字号、粗细、颜⾊、下划线等;设置段落的⾸⾏缩进、⾏距;设置页⾯页边距和纸张⼤⼩;设置页眉、页码;插⼊图⽚,设置图⽚宽⾼以及给图⽚添加标题;插⼊表格,格式化表格,往表格中插⼊数据;保存Word,打印Word;重新打开Word等。
Visual studio版本:Visual Studio 2012(2010应该也可以)准备⼯作:/*1. 添加引⽤COM⾥⾯的 Microsoft Word 12.0 Object. Library 引⽤(12.0表⽰Word 2007版本)2. 导命名空间using MSWord =Microsoft.Office.Interop.Word;using System.IO;using System.Reflection;3. 把引⽤中的Microsoft.Office.Interop.Word的“属性”中的嵌⼊互操作设为False*/以下是全部代码:(代码有点长,但请不要有压⼒,直接复制进去就能直接成功运⾏)1using System;2using System.Collections.Generic;3using System.Linq;4using System.Runtime.InteropServices;5using System.Text;6using MSWord = Microsoft.Office.Interop.Word;7using System.IO;8using System.Reflection;910namespace Console_WordSkill_All11 {12class Program13 {14static void Main(string[] args)15 {16object path; //⽂件路径变量17string strContent; //⽂本内容变量18 MSWord.Application wordApp; //Word应⽤程序变量19 MSWord.Document wordDoc; //Word⽂档变量2021 path = Environment.CurrentDirectory + "\\MyWord_Print.doc";22 wordApp = new MSWord.ApplicationClass(); //初始化2324 wordApp.Visible = true;//使⽂档可见2526//如果已存在,则删除27if (File.Exists((string)path))28 {29 File.Delete((string)path);30 }3132//由于使⽤的是COM库,因此有许多变量需要⽤Missing.Value代替33 Object Nothing = Missing.Value;34 wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);3536#region页⾯设置、页眉图⽚和⽂字设置,最后跳出页眉设置3738//页⾯设置39 wordDoc.PageSetup.PaperSize = MSWord.WdPaperSize.wdPaperA4;//设置纸张样式为A4纸40 wordDoc.PageSetup.Orientation = MSWord.WdOrientation.wdOrientPortrait;//排列⽅式为垂直⽅向41 wordDoc.PageSetup.TopMargin = 57.0f;42 wordDoc.PageSetup.BottomMargin = 57.0f;43 wordDoc.PageSetup.LeftMargin = 57.0f;44 wordDoc.PageSetup.RightMargin = 57.0f;45 wordDoc.PageSetup.HeaderDistance = 30.0f;//页眉位置4647//设置页眉48 wordApp.ActiveWindow.View.Type = MSWord.WdViewType.wdNormalView;//普通视图(即页⾯视图)样式49 wordApp.ActiveWindow.View.SeekView = MSWord.WdSeekView.wdSeekPrimaryHeader;//进⼊页眉设置,其中页眉边距在页⾯设置中已完成50 wordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphRight;//页眉中的⽂字右对齐515253//插⼊页眉图⽚(测试结果图⽚未插⼊成功)54 wordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;55string headerfile = @"C:\Users\xiahui\Desktop\OficeProgram\3.jpg";56 MSWord.InlineShape shape1 = wordApp.ActiveWindow.ActivePane.Selection.InlineShapes.AddPicture(headerfile, ref Nothing, ref Nothing, ref Nothing);57 shape1.Height = 5;//强⾏设置貌似⽆效,图⽚没有按设置的缩放——图⽚的⽐例并没有改变。
word域代码详解十个特殊指令(域开关),分别是:1.数组\A、2.括号\B、3.位移\D、4.分式\F、5.积分\I、6.列表\L、7.重叠\O、8.根号\R、9.上下标\S、10.框\X,每个开关又有若干个选项,用以精确调节格式。
1. 数组开关\A(): 按行顺序将数组元素排列为多列域代码:{EQ \a(100,2,31) }讲解:{EQ\列表(100,2,31排成一列)}可用参数:\al左对齐;\ac居中;\ar右对齐;\con元素排成n 列;\vsn 行间增加n 磅;\hsn列间增加n磅\al左对齐域代码:{EQ \a\al(100,2,31)}讲解:{EQ \列表\左对齐(100,2,31)}\ac居中域代码:{EQ \a\ac(100,2,31) }讲解:{EQ \列表\居中对齐(100,2,31)}\ar右对齐域代码:{EQ \a\ar(100,2,31) }讲解:{EQ \列表\右对齐(100,2,31)}\con元素排成n列域代码:{EQ \a\co3(10,2,31,0,1,0,14,3,55)}讲解:{EQ \列表\元素排成3列(10,2,31,0,1,0,14,3,55)}\vsn 行间增加n磅域代码:{EQ \a\co3\vs2(10,2,31,0,1,0,14,3,55)}讲解:{EQ \列表\元素排成3列\行间增加2磅}\hsn 列间增加n磅域代码:{EQ \a\co3\vs2\hs4(10,2,31,0,1,0,14,3,55)}讲解:{EQ \列表\元素排成3列\行间增加2磅\列间增加4磅}2. 括号开关\B(): 用大小适当的括号括住元素。
域代码:{EQ \b( \a(100,2,31)) }讲解:{EQ \加括号( \数组(100,2,31))}可用参数:左括号使用字符* \lc\*;右括号使用字符* \rc\* ;左右括号都使用字符* \bc\*\lc\* 左括号使用字符*域代码:{EQ \b\lc\|( \a(100,2,31))}讲解:{EQ \加括号\左括号使用字符|( \数组(100,2,31)) }\rc\* 右括号使用字符*域代码:{EQ \b\rc\|( \a(100,2,31)) }讲解:{EQ \加括号\右括号使用字符|( \数组(100,2,31))}\bc\* 左右括号都使用字符*域代码:{EQ \b\bc\|( \a(100,2,31)) }讲解:{EQ \加括号\左右括号使用字符|( \数组(100,2,31)) }注意:如果指定的字符*是{ 、[ 、( 、或<,Word 将使用相应的字符作为右括号。
C#操作word我们都知道,Office 是基于COM 组件技术开发的,属于非托管程序,然而C# 使用的都是托管程序,那么如何使用非托管的COM 组件就是我们操作WORD 的第一个问题。
所幸的是, .NET FRAMEWORK 提供了一种不同种类类库的转换工具tlbimp,exe ,通过这个转换工具,我们可以把COM 组件转化为 .NET FRAMEWORK 可以直接调用的DLL 文件。
接下来就是转化工作了,Office 组件都可以在C:Program FilesMicrosoft Office 目录下找到,当然安装的Office 版本不同,子目录是不一样的。
笔者使用的是Office 2007 ,可以在C:Program FilesMicrosoft OfficeOffice12 目录下找到MSWORD.OLB ,这个是WORD 组件的类库文件,还可以找到MSACC.OLB 操作ACCESS ,MSPPT.OLB 操作PPT ,XL5CHS32.OLB 操作EXCEL 。
载入不同的组件就可以完成对不同Office 组件的操作。
使用tlbimp,exe 工具转化MSWORD.OLB 文件后可以得到三个DLL 文件,Office ,dll ,Visual BasicIDE.dll ,Word .dll 。
最后在编译文件的时候,记得将这三个DLL 文件载入,命令如下:csc /r:system.dll /r:system.windows.forms.dll /r:system.drawing.dll /r:office .dll /r:vbide.dll /r:word .dll word .cs笔者使用Visual 2005 编译环境,通过IDE 提供的功能可以大大简化我们对组件转化的工作,并且在编译时也不需要输入那么繁杂的语句,非常方便了。
下面介绍一下IDE 载入Office 组件的方式。
在菜单栏选择“项目”-“添加引用”,弹出的窗口中我们可以选择“ COM ”选项卡,找到Microsoft Office 12.0 Object Library (Office 2003/2007 需要使用12.0 版的,如果你使用的是Office 2000 或者更低的版本,只要载入10.0 版的就可以了),确定后引入. 也可以在“浏览”选项卡下找到我们上面提到的MSWORD.OLB 文件,引入即可。
数据导出到Excel(或Word)源代码大全在日常工作中,大家都习惯Office作为办公软件,因此,在开发软件的时,常常会有把数据导出到Excel等Office软件的需求。
在此,收集一些常用的导出文件的源程序,希望给大家带来方便。
(不断更新)一、DataSet数据集内数据转化为Excel1.// 作用:把DataSet数据集内数据转化为Excel、Word文件2.// 描述:这些关于Excel、Word的导出方法,基本可以实现日常须要,其中有些方法可以把数据导出后3.// 生成Xml格式,再导入数据库!有些屏蔽内容没有去掉,保留下来方便学习参考用之。
4.// 备注:请引用Office相应COM组件,导出Excel对象的一个方法要调用其中的一些方法和属性。
5.public void DataSetToExcel(DataSet ds,string FileName)6.{7.try8.{9.//Web页面定义10. //System.Web.UI.Page mypage=new System.Web.UI.Page();11.12. HttpResponse resp;13. resp=HttpContext.Current.Response;14. resp.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");15. resp.AppendHeader("Content-disposition","attachment;filename="+FileName+".xls");16. resp.ContentType="application/ms-excel";17.18. //变量定义19. string colHeaders=null;20. string Is_item=null;21.22. //显示格式定义////////////////23.24.25. //文件流操作定义26. //FileStream fs=new FileStream(FileName,FileMode.Create,FileAccess.Write);27. //StreamWriter sw=new StreamWriter(fs,System.Text.Encoding.GetEncoding("GB2312"));28.29. StringWriter sfw=new StringWriter();30. //定义表对象与行对象,同时用DataSet对其值进行初始化31. System.Data.DataTable dt=ds.Tables[0];32. DataRow[] myRow=dt.Select();33. int i=0;34. int cl=dt.Columns.Count;35.36. //取得数据表各列标题,各标题之间以/t分割,最后一个列标题后加回车符37. for(i=0;i<cl;i++)38. {39. //if(i==(cl-1)) //最后一列,加/n40. // colHeaders+=dt.Columns[i].Caption.ToString();41. //else42. colHeaders+=dt.Columns[i].Caption.ToString()+"/t";43. }44. sfw.WriteLine(colHeaders);45. //sw.WriteLine(colHeaders);46.47. //逐行处理数据48. foreach(DataRow row in myRow)49. {50. //当前数据写入51. for(i=0;i<cl;i++)52. {53. //if(i==(cl-1))54. // Is_item+=row[i].ToString()+"/n";55. //else56. Is_item+=row[i].ToString()+"/t";57. }58. sfw.WriteLine(Is_item);59. //sw.WriteLine(Is_item);60. Is_item=null;61. }62. resp.Write(sfw);63. //resp.Clear();64. resp.End();65. }66. catch(Exception e)67. {68. throw e;69. }70.}二、DataSet数据集内数据转化为Excel文件(2)1./// <summary>2./// ExportFiles 的摘要说明。
Sub zhengti(ztgs)
'
' Macro2 Macro
' 宏在2008-10-31 由user 录制
''''''将相应格式的字母改为Times New Roman 正体Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = ztgs
.Replacement.text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Replacement.Font.Italic = False
End With
Selection.Find.Execute Replace:=wdReplaceAll End Sub
Sub xieti(ztgs)
' Macro2 Macro
' 宏在2008-10-31 由user 录制
''''''将所有的字母改为Times New Roman 斜体Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.text = ztgs
.Replacement.text = "^&"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Replacement.Font.Color = wdColorBlue
.Replacement.Font.Bold = True
.Replacement.Font.Italic = True
= "Times new roman"
Bi = "times new roman"
Other = "Times new roman"
Ascii = "Times new roman"
' .Replacement.font.
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Sub a物理符号斜体替换()
'
' Macro2 Macro
' 宏在2008-10-31 由user 录制
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''将所有的字母改为Times New Roman 斜体''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
xieti "^$" '''''将所有的字母改为Times New Roman 斜体加粗' zhengti "^#^$" '将数字后面的单位改为正体
zhengti "^#^$^$" '将数字后面的双字母单位改为正体
zhengti "^#^$/^$"
zhengti "^#^$/^$^$"
zhengti "^#^$^$/^$"
zhengti "^#^$/^$^$"
zhengti "^$." '将字母选项改为正体全角点.zhengti "^$." '将字母选项改为正体半角点. zhengti "sin" '将三角函数改为正体sin zhengti "cos" '将三角函数改为正体cos zhengti "tan" '将三角函数改为正体tan zhengti "min"
zhengti "rad"
zhengti "rad/s"
MsgBox "更改完毕,请检查并手动修改"
End Sub。