Hello All,
I am new to C# i have problem while reading the document.Actually my requirement is i have word document in this format:
1 Purpose
2 Test Specification
2.1 Test Details
2.2 Test Description
2.3 Test Strategy
3 Results
4 Remarks
1 Purpose: this will contain info
2 Test Specification : this will contain info
2.1 Test Details :: this will contain info
2.2 Test Description: this will contain info
2.3 Test Strategy: this will contain info
3 Results: this will contain info
4 Remarks: this will contain info
my question is i want to get the text of each item,how can this be acheived in C#.Kindly help me
Thank you,
Sampath
3 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Marina EberhardtPosted Dec 2, 2014, 5:37 AM
I'm not sure but I presume your document is formatted in a way that those listed items represent your document's chapters and that they have a heading styled title (at least that is a common thing to do in order to get a nice Table of Content from them).
So what you can do is iterate through all document's paragraphs and look for the ones that have appropriate styling. For example "1 Purpose", "2 Test Specification", "3 Results" and "4 Remarks" will probably have the "heading 1" style, while the "2.1 Test Details", "2.2 Test Description" and "2.3 Test Strategy" will have the "heading 2" style. And the easiest way that comes to my mind is to simply retrieve the text content between the two heading styled paragraphs.
For example try the following (note that I used a C# component for processing word files instead of calling a part of an PIA from C# (aka Word Interop):
And here is how you can use it:
Also just to point out the above sample shows how to process a DOCX file format in C#, but note that the same solution can be applied for processing a DOC file format in C# as well.
Ziggy RamPosted Oct 2, 2014, 9:21 AM
http://msdn.microsoft.com/en-US/library/vstudio/microsoft.office.tools.word
http://msdn.microsoft.com/library/vstudio/bb157891
I am currently implementing this feature in an internal-use application using leadtools OCR features that loads the MS Word DOC or DOX files as raster image, pass it to the OCR engine, recognize all the text in the rasterized image and then save the recognized text to any supported text or document format (including PDF, TXT, Doc, etc.). You can find more information here.
Selva GanapathyPosted Sep 29, 2014, 11:09 AM