Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
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;
        }



C#
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.
Posted
Updated 12-Jan-17 1:19am
Comments
ZurdoDev 12-Jan-17 7:18am    
You can actually record a macro and do what you need to and it will generate the code you need.

1 solution

You need to use loop, i.e.:
C#
for(int i=1;i<6;i++)
{
    var content= inputWord.GetRange(String.Format("Cost of {0}", i), "Rs.");
    //your code here
}

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900