07-15-2005 06:26 PM
07-16-2005 07:35 PM
You can do this by calling CNiWordDocument::GetDispatch to get the Word Document IDispatch pointer, then you can use the Word automation interfaces with this IDispatch pointer to perform opreations that aren't exposed by CNiWordDocument. In your case, you can get the Word automation PageSetup object from the document and then adjust the margins. For example, add the following to your stdafx.h (this assumes Office XP; the paths will change if you have an earlier version of Office):
#include "oleacc.h" #include "atlbase.h" #pragma warning(push) #pragma warning(disable: 4278) #import "C:\\Program Files\\Common Files\\Microsoft Shared\\Office10\\mso.dll" \ rename_namespace("OfficeXP") using namespace OfficeXP; #import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.olb" \ rename_namespace("VBE6") using namespace VBE6; #import "C:\\Program Files\\Microsoft Office\\Office10\\MSWORD.olb" \ rename("ExitWindows", "WordExitWindows") \ named_guids, \ rename_namespace("MSWord") using namespace MSWord; #pragma warning(pop)
The following example will move the left and right margins of the document in a little bit:
CNiWordApplication application; CNiWordDocument document = application.CreateDocument(); CComQIPtr<_Document> spDocument(document.GetDispatch(false)); PageSetupPtr spPageSetup = spDocument->PageSetup; spPageSetup->LeftMargin += 50.0f; spPageSetup->RightMargin += 50.0f;
Hope this helps.
- Elton
07-27-2005 04:10 PM
Thank you so much for your help!!
Yajai