Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating MsWord or Powerpoint document

Posted on 2001-07-26
8
Medium Priority
?
210 Views
Last Modified: 2013-11-25
Hi there,
Is it easy to create a microsoft word document (or powerpoint) with text and image from within Visual C++ / MFC? How?
If not from MFC, then, how?
Thanks,
cshwong
0
Comment
Question by:cshwong
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:migel
ID: 6321229
Hi!
you have to use MS_OFFICE COM objects:
to use it you have to import TLB shipped with MSoffice :

//for example for Excell:
#import "..\excel\mso97.dll" no_namespace rename("DocumentProperties", "DocumentPropertiesXL")
#import "..\excel\vbeext1.olb" no_namespace  rename("_CommandBars", "CommandBars")
#import "..\excel\excel8.olb" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") rename("_CommandBars", "CommandBars") no_dual_interfaces
using namespace Excel;

and later use it:
for example this code opens excel APP and run macro

     CoInitialize(NULL);
     _ApplicationPtr pXL;
     
    try {
          SetSpyHook(TRUE);
          pXL.CreateInstance(L"Excel.Application");
          pXL->Visible = VARIANT_TRUE;
          WorkbooksPtr pBooks = pXL->Workbooks;
          char szPath[_MAX_PATH];
          _getcwd(szPath, _MAX_PATH);
          if (szPath[strlen(szPath)-1] != '\\')
               strcat(szPath, "\\");
          strcat(szPath, "test.xla");
          _WorkbookPtr pBook  = pBooks->Open(_bstr_t(szPath));
          pXL->Run(_variant_t("test.xla!init_app"));
          }
     catch(_com_error &e)
          {
....
          }

0
 
LVL 12

Expert Comment

by:migel
ID: 6321232
SetSpyHook(TRUE); - delete this line (it is just working code remains)
0
 

Author Comment

by:cshwong
ID: 6321401
Thanks,
But, now to put text and position an image in an empty Word document?  
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 12

Expert Comment

by:migel
ID: 6321585
Hi You can look at TLB methods and find something usefull :-)
you can use InsertBefore to insert text at specific position in the document
and for bitmap you can add it in the Shapes collection
// in the basic (VBA)
ActiveDocument.Shapes.AddOLEObject _
    FileName:="c:\my documents\MyDrawing.bmp", _
    LinkToFile:=True

Also I recommend you open VBA editor in the Word and open opbject inspector here you found ALL methods provided by MSOffice Objects and also you found some usefull examples how to use it in the VBA (code for C++ looks same)
0
 

Author Comment

by:cshwong
ID: 6325255
Thanks to migel,

However, I am a dummy of COM.

I can't find mso97.dll in my harddisks.  What can I do?

I try VC++'s "tools"\"OLE/COM Object Viewer" and I am confused by the things.  I searched related topics in MSDN but I see many articles and just don't know where to start.  I really want to do it quick.

In MsWord, I cannot find "VBA editor"'s "Object Inspector".  I can only find "Visual Basic Editor"'s "Object Browser".

I would be grateful if you can help me further by listing the steps I should do in order to incoporate your code. [ I think I am an experienced MFC programmer, but is dummy to Visual Basic and COM ]

However, if you think that I should give up, please let me know.  I'll still send you the points.

Thanks anyway,
cshwong


0
 
LVL 12

Accepted Solution

by:
migel earned 400 total points
ID: 6325722
Hi!
Mso97.dll is the COM library for MSOffice 97.
if you have another version you need diffferent dll
for example for office 2000 you need:
mso9.dll
MSWORD9.OLB
also look at MSDN
Microsoft Office 2000 Developer Object Model Guide
and related topics

0
 

Author Comment

by:cshwong
ID: 6325736
Thanks to migel,

However, I am a dummy of COM.

I can't find mso97.dll in my harddisks.  What can I do?

I try VC++'s "tools"\"OLE/COM Object Viewer" and I am confused by the things.  I searched related topics in MSDN but I see many articles and just don't know where to start.  I really want to do it quick.

In MsWord, I cannot find "VBA editor"'s "Object Inspector".  I can only find "Visual Basic Editor"'s "Object Browser".

I would be grateful if you can help me further by listing the steps I should do in order to incoporate your code. [ I think I am an experienced MFC programmer, but is dummy to Visual Basic and COM ]

However, if you think that I should give up, please let me know.  I'll still send you the points.

Thanks anyway,
cshwong


0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9490553
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by : migel

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

885 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