views:

118

answers:

1

Does anyone know how to access the PageSetup properities of an Excel worksheet via COM from x++ code. I can do all the formatting I require for a custom report but can't access PageSetup object.

Any pointers / suggestions appreciated.

+1  A: 

http://axforum.info/forums/showthread.php?p=209139#post209139

#define.xlDialogPageSetup(7)
static void Job212(Args _args)
{
    COM doc = ; // HERE IS EXCEL DOCUMENT COM OBJECT
    COM app;
    COM worksheet;
    COM pageSetup;
    COM temp;

    int fitToPagesWide = 5; 
    int fitToPagesTall = 0; 

    COMVariant cvZoom = COMVariant::createFromBoolean(false);
    COMVariant cvWide = fitToPagesWide ? COMVariant::createFromInt( fitToPagesWide ) 
                                       : COMVariant::createFromBoolean( false );
    COMVariant cvTall = fitToPagesTall ? COMVariant::createFromInt( fitToPagesTall )
                                       : COMVariant::createFromBoolean( false )    ;
    ;
    app = doc.Application();

    worksheet = app.ActiveSheet();
    pageSetup = worksheet.PageSetup();

    pageSetup.Zoom(cvZoom);
    pageSetup.FitToPagesWide(cvWide);
    pageSetup.FitToPagesTall(cvTall);

    // это для демонстрации того, что получается
    temp = app.Dialogs();
    temp = temp.Item(#xlDialogPageSetup);
    temp.Show();
AxCoder