[Word 2007]搜索关键字并添加脚注 [英] [Word 2007]Searching for keywords and adding footnotes

查看:125
本文介绍了[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]搜索关键字并添加脚注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆