473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

C++ Word automation Extract text

Sub: C++ Word automation Extract text

hello.

I want extact text form a word document using a visual c++ programme.

I have see a lot of documentation. and my analysis is that I must use a
"word automation".

I have foud a lot of exemple to use it but I need your precious help to
use it properly.

I init my automation

...
CLSID clsid;
CLSIDFromProgID(L"Word.Application", &clsid);

IUnknown* pUnk;
HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_LOCAL_SERVER,
IID_IUnknown, (void**) &pUnk);
if (FAILED(hr))
{
OutputDebugString("Error in creating Word application instance\n");
Destroy();
return -1;
}

hr = pUnk->QueryInterface(IID_IDispatch, (void**)&m_pDispApp);

DISPPARAMS dp = { NULL, NULL, 0, 0 };
DISPID dispID;
LPOLESTR szDoc = L"Documents";
IDispatch* pDocuments = NULL;
VARIANT varRetVal;
hr = m_pDispApp->GetIDsOfNames(IID_NULL, &szDoc, 1,
LOCALE_SYSTEM_DEFAULT, &dispID);
hr = m_pDispApp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYGET, &dp, &varRetVal, NULL, NULL);
if (!SUCCEEDED(hr))
{
Destroy();
return -1;
}

m_pDocuments = varRetVal.pdispVal;
...
I open a word document

...
VARIANT varRetVal;
EXCEPINFO excepInfo; // this variable contains exception info if any
Invoke call fails
VARIANTARG varg;
varg.vt = VT_BSTR;
varg.bstrVal = _bstr_t(strFilePath); // this is the MS-word document
filename, must be changed to a valid filename that

exists on disk
DISPPARAMS dpOpen = { &varg, NULL, 1, 0 };
DISPID dispOpenID;
LPOLESTR szOpenDoc = L"Open";
HRESULT hr = m_pDocuments->GetIDsOfNames(IID_NULL, &szOpenDoc, 1,
LOCALE_SYSTEM_DEFAULT, &dispOpenID);
hr = m_pDocuments->Invoke(dispOpenID, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD, &dpOpen, &varRetVal, &excepInfo,

NULL);
if (FAILED(hr))
{
OutputDebugString("Error opening the document\n");
Destroy();
return -1;
}
...

a ms word programme open, <b>i dont want to see the MS Word application
to open</b>

How to read the word file w/o having the MSWord interface poping up ?
2. if the document is used, then, i see a message box that asks me to
chose between read-only, notifiy ..

I always have to open it as readonly (how can do this ?)
3. I have found how to save a doc document in txt file

...
VARIANT vNeuerName, vSpeichernFormat;
vNeuerName.vt = VT_BSTR;
vNeuerName.bstrVal = SysAllocString(L"C:\\delete\\docneu.txt");
vSpeichernFormat.vt = VT_I4;
vSpeichernFormat.lVal = 2;

printf("SAVE");
getchar();

IDispatch* pDocument = varRetVal.pdispVal;
DISPPARAMS dpSave = { NULL, NULL, 0, 0 };
DISPID dispSaveID;
LPOLESTR szSaveDoc = L"SaveAs";

hr = pDocument->GetIDsOfNames(IID_NULL, &szSaveDoc, 1,
LOCALE_SYSTEM_DEFAULT, &dispSaveID);
hr = pDocument->Invoke(dispSaveID, IID_NULL, LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD, &dpSave, &varRetVal, NULL, NULL);
...

But this code is invalid. Why ?

4. I only have to read the text from the .doc file and I would like to
avoid saving it in a other file
(how can do it ?)

Many Thank you for your help.

--
Mickeydisn
Visual C++ programmer.

Oct 3 '05 #1
1 12046
mi********@gmail.com wrote:
Sub: C++ Word automation Extract text

hello.

I want extact text form a word document using a visual c++ programme.

[snip]

This is off-topic in this newsgroup, which is concerned with standard
C++ only. Try a Microsoft-specific group like
comp.os.ms-windows.programmer.win32.

Cheers! --M

Oct 3 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ptaku25 | last post by:
Hello All, I would like to insert some text in specific location in MS Word document under app written in BCB6, location of the document I mean that I want to insert some text eg. after...
12
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000...
4
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can...
4
by: Daniel | last post by:
Hello, i have a problem with the word automation from c#. First, i want to mention, that i don't have any dependencies from word in my c#-project, i want to use the system.reflection model to...
56
by: Richard Grene | last post by:
using Word automation from vb.net how can I get to the bottom of the document? Thanks, Richard
4
by: shonend | last post by:
I am trying to extract the pattern like this : "SUB: some text LOT: one-word" Described, "SUB" and "LOT" are key words; I want those words, everything in between and one word following the...
7
by: teo | last post by:
hallo, I need to extract a word and few text that precedes and follows it (about 30 + 30 chars) from a long textual document. Like the description that Google returns when it has found a...
22
by: liya.tansky | last post by:
Hello, I'm developing an intranet (win XP, .NET 2, Visual Studio 2005, Microsoft.Office.Interop.Word.dll in references) and needed to implement find-replace in word doc before sending letter and...
6
by: Paul Mc | last post by:
Hi all, It's a little late in the day for me so please forgive as i need my bed.!! The issue is i need to open a word doc (say "c:\temp.doc) and paste into it, but i only can work out how...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.