By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,617 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Microsoft word document parsing using in C#.net

P: 1
can anyone one help me how to write the below code in C#.NET
i am able to create the wordapp and openthe document but further things like compare word document content and not able to.... plz help me
Expand|Select|Wrap|Line Numbers
  1. // Create an instance of Word
  2. if (!objWordApp.CreateDispatch("Word.Application")) 
  3. {
  4. SendMessage(m_pFRMgr->m_hActiveDlg,WM_TR_READ,0,(LONG)(LPCSTR)m_pFRMgr->m_strErrMsg);
  5. }
  6. objWordApp.SetVisible(FALSE);
  7. objDocs = objWordApp.GetDocuments();
  8. //open the word file
  9. lpDisp = objDocs.Open( COleVariant(strTRFile, VT_BSTR), covFalse,                    covFalse,covFalse,covOptional,covOptional,covFalse,covOptional,covOptional,covOptional);
  10. if(lpDisp == NULL)
  11. {
  12. if(objWordApp)
  13. objWordApp.Quit(covFalse, covFalse, covFalse);
  14. }
  15. objDoc.AttachDispatch(lpDisp);
  16. //Get word Source Doc ID: 
  17. objWords = objDoc.GetWords();
  18. int sizeWords = objWords.GetCount();
  19. CString strDocID;
  20. bool bSource = false;
  21. for(int cntWords=1; cntWords <= sizeWords; cntWords++)
  22. {
  23. Range objRange1;
  24. CString strWord;
  25. objRange1= objWords.Item(cntWords);
  26. strWord = objRange1.GetText();
  27. strWord.TrimLeft();
  28. strWord.TrimRight();
  29. if(strWord.CompareNoCase("Time") == 0)
  30. break;
  31. if(bSource && strWord.CompareNoCase(":") != 0)
  32. strDocID += strWord;
  33. }
Oct 11 '12 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,347
Compare it how? What are you trying to parse for? Without a description of these things, there's not much we can help with.
Oct 11 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.