[Word 2007]搜索关键字并添加脚注

编程入门 行业动态 更新时间:2024-10-28 04:15:50
本文介绍了[Word 2007]搜索关键字并添加脚注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嗨 我有一个要插入Word文档的HTML,其中包含## [some_number] ##标记.转换后,我需要找到它们并将其替换为脚注. 我的问题是:有没有一种有效的方法?我唯一能想到的是以下内容:

Hi I have a HTML I''m inserting into a Word document, that contains, among other things, ##[some_number]## tags. After the conversion I need to find them and replace them with footnotes. My question: is there an efficient way to do it? The only thing I can think of is the following:

//I only have one paragraph Range _range = pDoc.Paragraphs[1].Range; for (int i = 1; i <= _range.Words.Count; i++) { if (pDoc.Paragraphs[1].Range.Words[i].Text.EndsWith("##")) //some parsing to remove the ''##'' and get the number pDoc.Footnotes.Add(_range.Words[i].Characters[1], ref missing, ref text); }

现在这不是很有效,特别是在文档很长的情况下. 我试图使用Range.Find方法,但是我不知道如何从中获取合适的Range对象. 我会就此问题予以解决.

Now this is not very efficient, especially if the document is long. I was trying to use the Range.Find method, but I don''t know how to get the proper Range object from it. I''d appretiate any on the subject.

推荐答案

团队;) [Word 2007]搜索关键字并添加脚注 代码Snape.希望对您有帮助 使用使用Microsoft.Office.Interop.Word; 1. 打开Word文档 2. 通过单词document搜索SearchString 3. 如果找到,将其添加到脚注中 4. Kile文字处理器. 代码 Word.ApplicationClass wordApp =新的Word.ApplicationClass(); //输入框用于获取必须上传到文本框中的文件的路径. 字符串strPath = Request.PhysicalApplicationPath + @"document \ GTCS.doc"; //ShowWordMht1.FilePath ="CAREER.doc"; 目标文件= strPath; 对象nullobj = System.Reflection.Missing.Value; //在Document.Open上应该有9个参数. Word.Document doc = wordApp.Documents.Open(参考文件, ref nullobj,ref nullobj,ref nullobj,ref nullobj,ref nullobj, ref nullobj,ref nullobj,ref nullobj,ref nullobj,ref nullobj, ref nullobj,ref nullobj,ref nullobj,ref nullobj,ref nullobj); 字符串m_Content = wordApp.ActiveDocument.Content.Text; foreach(doc.words中的Microsoft.Office.Interop.Word.Range范围) { 如果(range.Text.Trim()== txtSearchWord.Text.Trim()) { //逻辑将其添加到脚注 } 其他 { lblDocContent.Text =搜索文本:-" + txtSearchWord.Text +找不到.!"; } wordwin.Attributes ["src"] ="document/GTCS.doc"; } wordApp.ActiveDocument.Close(ref nullobj,ref nullobj,ref nullobj); Killwordproc(); 谢谢's Prasanta Kumar Pradhan Hi Team ;) [Word 2007]Searching for keywords and adding footnotes Code snape. Hope It will Help to You Use using Microsoft.Office.Interop.Word; 1. Open The Word Document 2. Search The SearchString Through the word document 3. If Found Add it to the footnote 4. Kile the Word Processor. Code Word.ApplicationClass wordApp = new Word.ApplicationClass(); // Input box is used to get the path of the file which has to be uploaded into textbox. string strPath = Request.PhysicalApplicationPath + @"document\GTCS.doc"; //ShowWordMht1.FilePath = "CAREER.doc"; object file = strPath; object nullobj = System.Reflection.Missing.Value; // here on Document.Open there should be 9 arg. Word.Document doc = wordApp.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj); string m_Content = wordApp.ActiveDocument.Content.Text; foreach (Microsoft.Office.Interop.Word.Range range in doc.Words) { if (range.Text.Trim() == txtSearchWord.Text.Trim()) { //Logic Add it to the footnote } else { lblDocContent.Text = "The Search Text:- "+ txtSearchWord.Text + " Not Found. !"; } wordwin.Attributes["src"] = "document/GTCS.doc"; } wordApp.ActiveDocument.Close(ref nullobj, ref nullobj, ref nullobj); Killwordproc(); Thank''s Prasanta Kumar Pradhan

更多推荐

[Word 2007]搜索关键字并添加脚注

本文发布于:2023-11-24 15:27:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625781.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚注   搜索关键字   Word

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!