如何从word文件中获取特定内容 [英] How do I get specific content from word file

查看:89
本文介绍了如何从word文件中获取特定内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个输入word文档文件,内容如

成本1(2017年1月1日 - 2017年1月12日) ):50卢比。
2的成本(2017年1月3日至2017年1月12日):60卢比。
成本3(2017年1月5日至2017年1月12日):20卢比。
4日费用(2017年1月6日至2017年1月12日):10卢比。
5的成本(2017年1月8日至2017年1月12日):90卢比。



我需要将这些内容显示到我的输出word文件。我试过这个



  public 范围GetRange(对象 findText,对象 LastText)
{
范围range1 = doc.Content;
range1.Find.Execute(findText);
range1.Find.Execute(findText);

范围range2 = doc.Content;
range2.Find.Execute(LastText);
range2.Find.Execute(LastText);

if (range2.Start > range1.Start)
{
范围rng = doc.Range(range1.Start,range2.End);

return rng;
}
else
return ;
}







  var  content = inputWord.GetRange( 费用为1,< span class =code-string>  Rs。); 





但我得到两行成本为1,成本为2.那么如何获得所有五个成本的frrom word文件?



我尝试了什么:



我试过从word中获取内容作为范围。

解决方案

你需要使用循环,即:

   int  i =  1 ; i< 6; i ++)
{
var content = inputWord.GetRange( String .Format( 成本{0},i), Rs。);
// 您的代码
}

< br $> b $ b或

  int  i =  1 ; 
执行
{
var content = inputWord.GetRange(< span class =code-sdkkeyword> String
.Format( 费用{0},i), Rs。);
// 此处的代码
i + = 1 ;
} while (content!= null );


Hi,
   
I have one input word document file with content like
 
Cost of 1 (1 Jan 2017 -12 Jan 2017): 50 Rs .       
Cost of 2(3 Jan 2017 -12 Jan 2017): 60 Rs .       
Cost of 3(5 Jan 2017 -12 Jan 2017): 20 Rs .   
Cost of 4(6 Jan 2017 -12 Jan 2017): 10 Rs . 
Cost of 5(8 Jan 2017-12 Jan 2017): 90 Rs .


I need to display these contents to my output word file.I tried with this

public Range GetRange(object findText, object LastText)
        {
            Range range1 = doc.Content;
            range1.Find.Execute(findText);
            range1.Find.Execute(findText);
    
            Range range2 = doc.Content;
            range2.Find.Execute(LastText);
            range2.Find.Execute(LastText);
    
            if (range2.Start > range1.Start)
            {               
                Range rng = doc.Range(range1.Start, range2.End);
    
                return rng;
            }
            else
                return null;
        }




var content= inputWord.GetRange("Cost of 1", "Rs.");



But I get two lines cost of 1 and cost of 2.So how to get all the five cost frrom word file?

What I have tried:

I have tried with get content from word as range.

解决方案

You need to use loop, i.e.:

for(int i=1;i<6;i++)
{
    var content= inputWord.GetRange(String.Format("Cost of {0}", i), "Rs.");
    //your code here
}


or

int i= 1;
do
{
    var content= inputWord.GetRange(String.Format("Cost of {0}", i), "Rs.");
    //your code here
    i+=1;
} while(content!=null);


这篇关于如何从word文件中获取特定内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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