想对word文档的文本进行修改.也就是替换Word.Application wp = new Word.ApplicationClass(); Word.Document wd = wp.Documents.Open(ref filename, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue);wDoc.Content.Text = wDoc.Content.Text.Replace("测试", "OK");如果按上面用replace的话整个文档的布局就乱了,全部居中了,有朋友遇到过指点下
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue);wDoc.Content.Text = wDoc.Content.Text.Replace("测试", "OK");如果按上面用replace的话整个文档的布局就乱了,全部居中了,有朋友遇到过指点下
解决方案 »
- 请大家帮忙看看源码,为什么生成的Gzip文件解压后打开显示全是NULL?
- 路过的帮看一下!
- 关于webclient DownloadStringAsync问题
- 问个比较有意思的问题,关于静态参数!
- 一个winform程序给个人用户使用,请问使用什么数据库比较合适?
- 怎样判断客户端是否在线
- 如何得到dataGrid鼠标选中的内容?
- 自己写的用户控件,如何控制构造函数在设计的时候不运行部分代码?
- winform项目属性问题
- C#.NET我用jquery写的动态添加和删除,保存的时候不会写了。求大神解决,在线等。请在 btnSaveClick() 补充代码,万分感谢了。
- 获取Excel选定的单元格
- 不用EXCEL组件生成多SHEET的EXCEL文件
object replacewith = "沪A234";
object replace;Word.Application wp = new Word.ApplicationClass(); Word.Document wd = wp.Documents.Open(ref filename, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue);
wp.Selection.Find.Execute(ref findtext,ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue,
ref replacewith, ref replace,
ref MissingValue, ref MissingValue,
ref MissingValue, ref MissingValue);
wd.save();
这样子可以替换得.可是程序只查到第一个附合的价不进行下去.对replace不懂怎么给值;
试过给object replace = "wdReplaceAll",不行.高手们帮帮忙呀,
参阅应用于示例特性应用于 Find 对象的 Execute 方法。运行指定的查找操作。如果查找成功,则返回 True。Boolean 类型。expression.Execute(FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, Format, ReplaceWith, Replace, MatchKashida, MatchDiacritics, MatchAlefHamza, MatchControl)
expression 必需。该表达式返回 Find 对象。FindText Variant 类型,可选。指定需搜索的文本。可用空字符串 ("") 搜索格式,也可通过指定相应的字符代码搜索特殊字符。例如,“^p”对应段落标记,“^t”对应制表符。有关可以使用的特殊字符列表,请参阅查找和替换文本或其他项。MatchCase Variant 类型,可选。如果为 True,则指定查找文本区分大小写。相当于“编辑”菜单“查找和替换”对话框中的“区分大小写”复选框。MatchWholeWord Variant 类型,可选。如果为 True,则查找操作只定位于完全匹配的单词,而并非长单词中的部分文字。相当于“查找和替换”对话框中的“全字匹配”复选框。MatchWildcards Variant 类型,可选。如果为 True,则查找的文字包含特殊搜索操作符。相当于“查找和替换”对话框中的“使用通配符”复选框。MatchSoundsLike Variant 类型,可选。如果为 True,则查找操作定位于与要查找的文字发音相近的单词。相当于“查找和替换”对话框中的“同音”复选框。MatchAllWordForms Variant 类型,可选。如果为 True,则查找操作定位于要查找的文字的所有形式(例如,查找“sit”的同时,还查找“sitting”和“sat”),相当于“查找和替换”对话框中的“查找单词的各种形式”复选框。Forward Variant 类型,可选。如果为 True,则向下(向文档尾部)搜索。Wrap Variant 类型,可选。如果搜索从不是文档的起始位置开始,并已搜索到文档的末尾(如 Forward 设置为 False,则相反),用本参数控制接下来的操作。当存在选定内容或区域,而又没有在该选定内容或区域中找到搜索文字时,也可用本参数控制接下来的操作。可取下列 WdFindWrap 常量之一。WdFindWrap 可以是下列 WdFindWrap 常量之一:
wdFindAsk 搜索完选定内容或者区域后,Microsoft Word 会显示一条消息,询问是否搜索文档的其他部分。
wdFindContinue 到达搜索区域的开始或者结尾时,继续执行查找操作。
wdFindStop 到达搜索区域的开始或者结尾时,停止执行查找操作。 Format Variant 类型,可选。如果为 True,则查找操作定位于格式或带格式的文本,而不是查找文本。ReplaceWith Variant 类型,可选。替换文字。若要删除由 Find 参数指定的文字,可使用空字符串 ("")。与 Find 参数相似,本参数也可以指定特殊的字符和高级搜索条件。若要将图形对象或者其他非文本项指定为替换内容,可将这些项置于“剪贴板”上,然后将 ReplaceWith 指定为“^c”。Replace Variant 类型,可选。指定执行替换的个数:一个、全部或者不替换。可取下列 WdReplace 常量之一。WdReplace 可以是下列 WdReplace 常量之一:
wdReplaceAll
wdReplaceNone
wdReplaceOne MatchKashida Variant 类型,可选。如果为 True,则查找结果应与阿拉伯语文档中区分 kashidas 的文本相匹配。由于选择或安装的语言支持不同(例如,英语(美国)),此参数可能不可用。MatchDiacritics Variant 类型,可选。如果为 True,则查找操作在从右向左的语言的文档中按照匹配音调符号来匹配文字。由于选择或安装的语言支持不同(例如,英语(美国)),此参数可能不可用。MatchAlefHamza Variant 类型,可选。如果为 True,则在阿拉伯语文档中,查找内容应与区分 Alef Hamzas 的文本相匹配。由于选择或安装的语言支持不同(例如,英语(美国)),此参数可能不可用。MatchControl Variant 类型,可选。如果为 True,则在从右向左的语言的文档中,查找内容应与区分双向控制字符的文本相匹配。由于选择或安装的语言支持不同(例如,英语(美国)),此参数可能不可用。说明
如果 MatchWildcards 为 True,可为 FindText 参数指定通配符和其他高级搜索准则,例如,“*(ing)”查找任何以“ing”结尾的单词。若要搜索符号字符,可键入脱字符号 (^)、零 (0),然后键入符号字符的代码。例如,“^0151”对应一条长划线 (—)。除非另外指定,否则替换文本将沿用文档中被替换文本的格式。例如,如果用“xyz”替换字符串“abc”,那么加粗“abc”将被加粗字符串“xyz”所替换。另外,如果 MatchCase 为 False,那么查找到的大写文本将被大写的替换文本替换,而无论搜索文本和替换文本是否大小写。上例中,“ABC”将被“XYZ”替换。
试过给object replace = "wdReplaceAll",不行.高手们帮帮忙呀,Replace Variant 类型,可选。指定执行替换的个数:一个、全部或者不替换。可取下列 WdReplace 常量之一。WdReplace 可以是下列 WdReplace 常量之一:
wdReplaceAll
wdReplaceNone
wdReplaceOne 这样赋值就可以了
object Replace=Microsoft.Office.Interop.Word.WdReplace.wdReplaceAll;