Solved

Programatically parsing a Word doucment using C# and COM

Posted on 2004-10-13
9
158 Views
Last Modified: 2010-04-15
Hello,

I am trying to build a C# Windows application (using COM) and using an openFileDialog control; point to an MS Word document, parse the Word document, add the parsed contents to an array, extract the items in the array that I need using regular expression comparisons, and build an Excel document for the output.  The issue I am having is actually opening the MS Word document and extracting the text.  Any help is appreciated.

Tom
0
Comment
Question by:Thomas_H_68
  • 4
  • 3
9 Comments
 
LVL 6

Expert Comment

by:KingDumbNo
ID: 12300337
Hi Tom.
Take a look at this question:
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_20389638.html
and particularly the last comment.

The .NET framework and COM do not play well together.

Regards,
Emory
0
 

Author Comment

by:Thomas_H_68
ID: 12300541
Understood - I don't need speed and realize the depth of the question.  I am basically attempting proof of concept so VBA is not an option.  I will try to modify the example given and will update this question based upon the outcome.

Thank you,
Tom
0
 
LVL 6

Expert Comment

by:KingDumbNo
ID: 12300634
I don't understand the "VBA is not an option" phrase.  VB 6.0 or VBA _is_ the way to go, imho.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Thomas_H_68
ID: 12300692
The idea is to do this completely within a C# windows application with all internal operations transparent to the user - it is a proof of concept.  Are you suggesting accessing a VBA object through the C# windows app?

Tom
0
 
LVL 6

Expert Comment

by:KingDumbNo
ID: 12301084
It is most certainly doable in C#, just not as easy as it is from a VB 6.0 application believe it or not.  VBA doesn't make sense if this is to be more or less transparent to the user.  If you do end up going that route then I'd say start the application by the user opening an Excel template.  I'm not sure of the regex ability from VBA though.  Sorry I don't have the time to go into detail on all of the steps necessary.  I see this was your first question ever on EE.  If you have unlimited question points then I suggest opening a new question with this title:
"Need help accessing text in a Word document and writing to Excel, using C# is a requirement"
One thing more to make clear is that this is transparent to the user.  Does the user select the file?

Again, sorry I'm not much help.  Asking the new question may get you more coverage.

Regards,
Emory
0
 

Author Comment

by:Thomas_H_68
ID: 12301525
Yes, the ability for the user to select the Word doc is a requirement.  I have the application to the point where it opens the user selected Word doc file (this open file is not visible to the user nor should it be) so the next step is iterating through the file extracting the text.

Tom
0
 
LVL 6

Accepted Solution

by:
KingDumbNo earned 500 total points
ID: 12301978
Sounds like you're close.  I would suggest opening up Word, go into VBA (Alt+F11) and looking at the object model for an idea of what is available.  Just keep in mind accessing the methods are a little different.  (E.g., get_ added to the beginning of some methods).  I won't be checking this anymore today, so good luck.  I check the progress tomorrow.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now