Word in C++
-
Greetings I have been able to automate Word using my application. I have been able to write three lines of text into it. Now how should I create tables and format text in it. Now how should I add tables for formatting. Ritesh Below is the code which i am using ============================================================================= #include #include int main(int argc, char* argv[]) { // ******************* Declare Some Variables ******************** // Variables that will be used and re-used in our calls DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0}; VARIANT vResult; OLECHAR FAR* szFunction; BSTR bstrTemp; // IDispatch pointers for Word's objects IDispatch* pDispDocs; //Documents collection IDispatch* pDispSel; //Selection object IDispatch* pDispActiveDoc; //ActiveDocument object // DISPID's DISPID dispid_Docs; //Documents property of Application object DISPID dispid_DocsAdd; //Add method of Documents collection //object DISPID dispid_Sel; //Selection property of Applicaiton object DISPID dispid_TypeText; //TypeText method of Selection object DISPID dispid_TypePara; //TypeParagraph method of Selection object DISPID dispid_ActiveDoc; //ActiveDocument property of Application //obj DISPID dispid_SaveAs; //SaveAs method of the Document object DISPID dispid_Quit; //Quit method of the Application object // ******************** Start Automation *********************** //Initialize the COM libraries ::CoInitialize(NULL); // Create an instance of the Word application and obtain the pointer // to the application's IDispatch interface. CLSID clsid; CLSIDFromProgID(L"Word.Application", &clsid); IUnknown* pUnk; HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_SERVER, IID_IUnknown, (void**) &pUnk); IDispatch* pDispApp; hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispApp); // Get IDispatch* for the Documents collection object szFunction = OLESTR("Documents"); hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_Docs); hr = pDispApp->Invoke (dispid_Docs, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dpNoArgs, &vResult,
-
Greetings I have been able to automate Word using my application. I have been able to write three lines of text into it. Now how should I create tables and format text in it. Now how should I add tables for formatting. Ritesh Below is the code which i am using ============================================================================= #include #include int main(int argc, char* argv[]) { // ******************* Declare Some Variables ******************** // Variables that will be used and re-used in our calls DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0}; VARIANT vResult; OLECHAR FAR* szFunction; BSTR bstrTemp; // IDispatch pointers for Word's objects IDispatch* pDispDocs; //Documents collection IDispatch* pDispSel; //Selection object IDispatch* pDispActiveDoc; //ActiveDocument object // DISPID's DISPID dispid_Docs; //Documents property of Application object DISPID dispid_DocsAdd; //Add method of Documents collection //object DISPID dispid_Sel; //Selection property of Applicaiton object DISPID dispid_TypeText; //TypeText method of Selection object DISPID dispid_TypePara; //TypeParagraph method of Selection object DISPID dispid_ActiveDoc; //ActiveDocument property of Application //obj DISPID dispid_SaveAs; //SaveAs method of the Document object DISPID dispid_Quit; //Quit method of the Application object // ******************** Start Automation *********************** //Initialize the COM libraries ::CoInitialize(NULL); // Create an instance of the Word application and obtain the pointer // to the application's IDispatch interface. CLSID clsid; CLSIDFromProgID(L"Word.Application", &clsid); IUnknown* pUnk; HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_SERVER, IID_IUnknown, (void**) &pUnk); IDispatch* pDispApp; hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispApp); // Get IDispatch* for the Documents collection object szFunction = OLESTR("Documents"); hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_Docs); hr = pDispApp->Invoke (dispid_Docs, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dpNoArgs, &vResult,
http://www.codeproject.com/com/xoffice.asp Papa Murex Co. while (TRUE) Papa.WillLove ( Bebe ) ;
-
Greetings I have been able to automate Word using my application. I have been able to write three lines of text into it. Now how should I create tables and format text in it. Now how should I add tables for formatting. Ritesh Below is the code which i am using ============================================================================= #include #include int main(int argc, char* argv[]) { // ******************* Declare Some Variables ******************** // Variables that will be used and re-used in our calls DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0}; VARIANT vResult; OLECHAR FAR* szFunction; BSTR bstrTemp; // IDispatch pointers for Word's objects IDispatch* pDispDocs; //Documents collection IDispatch* pDispSel; //Selection object IDispatch* pDispActiveDoc; //ActiveDocument object // DISPID's DISPID dispid_Docs; //Documents property of Application object DISPID dispid_DocsAdd; //Add method of Documents collection //object DISPID dispid_Sel; //Selection property of Applicaiton object DISPID dispid_TypeText; //TypeText method of Selection object DISPID dispid_TypePara; //TypeParagraph method of Selection object DISPID dispid_ActiveDoc; //ActiveDocument property of Application //obj DISPID dispid_SaveAs; //SaveAs method of the Document object DISPID dispid_Quit; //Quit method of the Application object // ******************** Start Automation *********************** //Initialize the COM libraries ::CoInitialize(NULL); // Create an instance of the Word application and obtain the pointer // to the application's IDispatch interface. CLSID clsid; CLSIDFromProgID(L"Word.Application", &clsid); IUnknown* pUnk; HRESULT hr = ::CoCreateInstance( clsid, NULL, CLSCTX_SERVER, IID_IUnknown, (void**) &pUnk); IDispatch* pDispApp; hr = pUnk->QueryInterface(IID_IDispatch, (void**)&pDispApp); // Get IDispatch* for the Documents collection object szFunction = OLESTR("Documents"); hr = pDispApp->GetIDsOfNames (IID_NULL, &szFunction, 1, LOCALE_USER_DEFAULT, &dispid_Docs); hr = pDispApp->Invoke (dispid_Docs, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dpNoArgs, &vResult,
It looks like you have a working technique to communicate with the Word app. If you are asking about the specific commands to issue to word to create the table and do the formatting, I suggest you let the Word program tell you. Turn on the macro recorder, perform the operations of interest (create table). Then turn off the recorder and read the macro. It will contain the commands you need to implement. The implementation is just like the stuff you already have coded.
-
It looks like you have a working technique to communicate with the Word app. If you are asking about the specific commands to issue to word to create the table and do the formatting, I suggest you let the Word program tell you. Turn on the macro recorder, perform the operations of interest (create table). Then turn off the recorder and read the macro. It will contain the commands you need to implement. The implementation is just like the stuff you already have coded.
Thanks...I will take a look at it. Ritesh