Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sun May 08, 2016 9:08 pm

Hi,

Im interested in next thing: is it possible to make some template to use it in extracting data from word document or its better to make regex to extract data? Please, give me some optimal direction how to do it. Attached sample document from where I need to exctrat each column and row data. Using Spire.Doc trial from NuGet.

maximka19
 
Posts: 8
Joined: Sun May 08, 2016 8:43 pm

Mon May 09, 2016 3:58 am

Hi,

Thanks for your posting.
Sorry that I am not sure your requirement. Do you want to extract all data? or others?
Code: Select all
   //Load word document
    Document doc = new Document("D:\\Example.docx");
   //exctrat all data
    string content = doc.GetText();


   //Create a regex
    Regex regex = new Regex(@"\d\d\.\d\d\.\d\d");
   //Find all data matching the regex
    TextSelection[] selections = doc.FindAllPattern(regex);

Please give us an example to clarify your requirement. Thank you for your assistance.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Mon May 09, 2016 10:10 am

Than You for answer!

Sorry for my english, let me clarify question. I've attached document, where colored text with Red is the data i need to get. And Underlined colored red text is the data which parser should specify its Credit or Debit. Debits located in center, Credits in right-alignment: I've marked them in green color. How can I do this? Is that possible?

Thank You

maximka19
 
Posts: 8
Joined: Sun May 08, 2016 8:43 pm

Tue May 10, 2016 2:53 am

Hi,

Thanks for your further clarification.
The colored text with Red data you want to get cannot use regex to retrieve due to the data don't have same regular.
There is a solution to specify Credit or Debit of underlined colored red text.
Code: Select all
           Document doc = new Document("D:\\Example.docx");

            TextSelection selection1 = doc.FindString("200,000.00",true,true);
            TextRange range1 = selection1.GetAsOneRange();
            range1.Text = range1.Text + "(this is debit)";
       
            TextSelection selection2 = doc.FindString("22,960.00", true, true);
            TextRange range2 = selection2.GetAsOneRange();
            range2.Text = range2.Text + "(this is credit)";   

            string result = "result.docx";
            doc.SaveToFile(result,FileFormat.Docx);


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Tue May 10, 2016 8:19 am

Okay, thank You!

maximka19
 
Posts: 8
Joined: Sun May 08, 2016 8:43 pm

Wed May 11, 2016 1:20 am

Hi,

Welcome to feel free to contact us if you need further assistance.
Have a nice day.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2767
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc