Board index » delphi » Setting Page Adjustment, Page Orientation and Margins Of An Excel Workbook from Excel

Setting Page Adjustment, Page Orientation and Margins Of An Excel Workbook from Excel

Hello!

I need to do the following to an Excel workbook through Delphi.

Set the page adjustment level to 87%
Set the top and bottom margins to 1
Set the left and right margins to 0.9
Set the page orientation to landscape.

Can anyone provide a code snippet to do the above?

Cheers

Paul

 

Re:Setting Page Adjustment, Page Orientation and Margins Of An Excel Workbook from Excel


This doesn't answer the whole question but the following snippet does deal
with margins.

procedure SetPagePrintMargins(XLApp: TExcelApplication; XLChart:
TExcelChart; LMargin, RMargin, BMartin, TMargin:
  Single);
begin
  with xlchart.pagesetup do
    begin
      LeftMargin := xlapp.InchesToPoints(LMargin, lcid);
      RightMargin := xlapp.InchesToPoints(RMargin, lcid);
      BottomMargin := xlapp.InchesToPoints(BMartin, lcid);
      TopMargin := xlapp.InchesToPoints(TMargin, lcid);
    end;
end;

Quote
"Paul Saxton" <psax...@onetel.net.uk> wrote in message

news:3c93ef84$1_2@dnews...
Quote
> Hello!

> I need to do the following to an Excel workbook through Delphi.

> Set the page adjustment level to 87%
> Set the top and bottom margins to 1
> Set the left and right margins to 0.9
> Set the page orientation to landscape.

> Can anyone provide a code snippet to do the above?

> Cheers

> Paul

Re:Setting Page Adjustment, Page Orientation and Margins Of An Excel Workbook from Excel


Hi John!

What unit is TMargin declared in?  I am using Excel 2000 with Delphi 5.
Also, any chance of seeing the code that creates the margins?

Cheers

Paul

Quote
"John Hill" <j...@jbeh.com> wrote in message news:3c943f4d_1@dnews...
> This doesn't answer the whole question but the following snippet does deal
> with margins.

> procedure SetPagePrintMargins(XLApp: TExcelApplication; XLChart:
> TExcelChart; LMargin, RMargin, BMartin, TMargin:
>   Single);
> begin
>   with xlchart.pagesetup do
>     begin
>       LeftMargin := xlapp.InchesToPoints(LMargin, lcid);
>       RightMargin := xlapp.InchesToPoints(RMargin, lcid);
>       BottomMargin := xlapp.InchesToPoints(BMartin, lcid);
>       TopMargin := xlapp.InchesToPoints(TMargin, lcid);
>     end;
> end;

> "Paul Saxton" <psax...@onetel.net.uk> wrote in message
> news:3c93ef84$1_2@dnews...
> > Hello!

> > I need to do the following to an Excel workbook through Delphi.

> > Set the page adjustment level to 87%
> > Set the top and bottom margins to 1
> > Set the left and right margins to 0.9
> > Set the page orientation to landscape.

> > Can anyone provide a code snippet to do the above?

> > Cheers

> > Paul

Re:Setting Page Adjustment, Page Orientation and Margins Of An Excel Workbook from Excel


Paul - You have misunderstood the parameters of my procedure - The newsgroup
wordwrap doesn't help.

TMargin is my abbreviation for the "top" margin parameter that I am passing
into the procedure.

So the call is something like.

SetPagePrintMargins (MyExcelApp,  MyChart,  0.75,  1.15  ,0.75  ,0.67  );

The *numbers* are the left , right , bottom and top margin values (expressed
in inches) respectively - here the top margin ( tMargin)  then has the value
0.67.

So for your example I'd call something like.

SetPagePrintMargins (MyExcelApp,  MyChart,  0.9,  0.9  ,1.0  ,1.0  );

(assuming you are working in inches)

Quote
"Paul Saxton" <psax...@onetel.net.uk> wrote in message

news:3c945db7$1_1@dnews...
Quote
> Hi John!

> What unit is TMargin declared in?  I am using Excel 2000 with Delphi 5.
> Also, any chance of seeing the code that creates the margins?

> Cheers

> Paul

> "John Hill" <j...@jbeh.com> wrote in message news:3c943f4d_1@dnews...
> > This doesn't answer the whole question but the following snippet does
deal
> > with margins.

> > procedure SetPagePrintMargins(XLApp: TExcelApplication; XLChart:
> > TExcelChart; LMargin, RMargin, BMartin, TMargin:
> >   Single);
> > begin
> >   with xlchart.pagesetup do
> >     begin
> >       LeftMargin := xlapp.InchesToPoints(LMargin, lcid);
> >       RightMargin := xlapp.InchesToPoints(RMargin, lcid);
> >       BottomMargin := xlapp.InchesToPoints(BMartin, lcid);
> >       TopMargin := xlapp.InchesToPoints(TMargin, lcid);
> >     end;
> > end;

> > "Paul Saxton" <psax...@onetel.net.uk> wrote in message
> > news:3c93ef84$1_2@dnews...
> > > Hello!

> > > I need to do the following to an Excel workbook through Delphi.

> > > Set the page adjustment level to 87%
> > > Set the top and bottom margins to 1
> > > Set the left and right margins to 0.9
> > > Set the page orientation to landscape.

> > > Can anyone provide a code snippet to do the above?

> > > Cheers

> > > Paul

Re:Setting Page Adjustment, Page Orientation and Margins Of An Excel Workbook from Excel


Thanks for clearing that up John!

That all works now, one more question though what is the value for A4 paper
when setting the paper size?

Cheers

Paul

Quote
"John Hill" <j...@jbeh.com> wrote in message news:3c9501b0_1@dnews...
> Paul - You have misunderstood the parameters of my procedure - The
newsgroup
> wordwrap doesn't help.

> TMargin is my abbreviation for the "top" margin parameter that I am
passing
> into the procedure.

> So the call is something like.

> SetPagePrintMargins (MyExcelApp,  MyChart,  0.75,  1.15  ,0.75  ,0.67  );

> The *numbers* are the left , right , bottom and top margin values
(expressed
> in inches) respectively - here the top margin ( tMargin)  then has the
value
> 0.67.

> So for your example I'd call something like.

> SetPagePrintMargins (MyExcelApp,  MyChart,  0.9,  0.9  ,1.0  ,1.0  );

> (assuming you are working in inches)

> "Paul Saxton" <psax...@onetel.net.uk> wrote in message
> news:3c945db7$1_1@dnews...
> > Hi John!

> > What unit is TMargin declared in?  I am using Excel 2000 with Delphi 5.
> > Also, any chance of seeing the code that creates the margins?

> > Cheers

> > Paul

> > "John Hill" <j...@jbeh.com> wrote in message news:3c943f4d_1@dnews...
> > > This doesn't answer the whole question but the following snippet does
> deal
> > > with margins.

> > > procedure SetPagePrintMargins(XLApp: TExcelApplication; XLChart:
> > > TExcelChart; LMargin, RMargin, BMartin, TMargin:
> > >   Single);
> > > begin
> > >   with xlchart.pagesetup do
> > >     begin
> > >       LeftMargin := xlapp.InchesToPoints(LMargin, lcid);
> > >       RightMargin := xlapp.InchesToPoints(RMargin, lcid);
> > >       BottomMargin := xlapp.InchesToPoints(BMartin, lcid);
> > >       TopMargin := xlapp.InchesToPoints(TMargin, lcid);
> > >     end;
> > > end;

> > > "Paul Saxton" <psax...@onetel.net.uk> wrote in message
> > > news:3c93ef84$1_2@dnews...
> > > > Hello!

> > > > I need to do the following to an Excel workbook through Delphi.

> > > > Set the page adjustment level to 87%
> > > > Set the top and bottom margins to 1
> > > > Set the left and right margins to 0.9
> > > > Set the page orientation to landscape.

> > > > Can anyone provide a code snippet to do the above?

> > > > Cheers

> > > > Paul

Re:Setting Page Adjustment, Page Orientation and Margins Of An Excel Workbook from Excel


Suggest you try

PageSetup.PaperSize := XLPaperA4;

and while I'm at it I've found the way to set "orientation"

PageSetup.Orientation := xlLandscape;

All these variables can be easily found in the Excel Visual Basic Help file
in Excel 2000

John

Quote
"Paul Saxton" <psax...@onetel.net.uk> wrote in message

news:3c951edb$1_2@dnews...
Quote
> Thanks for clearing that up John!

> That all works now, one more question though what is the value for A4
paper
> when setting the paper size?

> Cheers

> Paul

> "John Hill" <j...@jbeh.com> wrote in message news:3c9501b0_1@dnews...
> > Paul - You have misunderstood the parameters of my procedure - The
> newsgroup
> > wordwrap doesn't help.

> > TMargin is my abbreviation for the "top" margin parameter that I am
> passing
> > into the procedure.

> > So the call is something like.

> > SetPagePrintMargins (MyExcelApp,  MyChart,  0.75,  1.15  ,0.75
,0.67  );

> > The *numbers* are the left , right , bottom and top margin values
> (expressed
> > in inches) respectively - here the top margin ( tMargin)  then has the
> value
> > 0.67.

> > So for your example I'd call something like.

> > SetPagePrintMargins (MyExcelApp,  MyChart,  0.9,  0.9  ,1.0  ,1.0  );

> > (assuming you are working in inches)

> > "Paul Saxton" <psax...@onetel.net.uk> wrote in message
> > news:3c945db7$1_1@dnews...
> > > Hi John!

> > > What unit is TMargin declared in?  I am using Excel 2000 with Delphi
5.
> > > Also, any chance of seeing the code that creates the margins?

> > > Cheers

> > > Paul

> > > "John Hill" <j...@jbeh.com> wrote in message news:3c943f4d_1@dnews...
> > > > This doesn't answer the whole question but the following snippet
does
> > deal
> > > > with margins.

> > > > procedure SetPagePrintMargins(XLApp: TExcelApplication; XLChart:
> > > > TExcelChart; LMargin, RMargin, BMartin, TMargin:
> > > >   Single);
> > > > begin
> > > >   with xlchart.pagesetup do
> > > >     begin
> > > >       LeftMargin := xlapp.InchesToPoints(LMargin, lcid);
> > > >       RightMargin := xlapp.InchesToPoints(RMargin, lcid);
> > > >       BottomMargin := xlapp.InchesToPoints(BMartin, lcid);
> > > >       TopMargin := xlapp.InchesToPoints(TMargin, lcid);
> > > >     end;
> > > > end;

> > > > "Paul Saxton" <psax...@onetel.net.uk> wrote in message
> > > > news:3c93ef84$1_2@dnews...
> > > > > Hello!

> > > > > I need to do the following to an Excel workbook through Delphi.

> > > > > Set the page adjustment level to 87%
> > > > > Set the top and bottom margins to 1
> > > > > Set the left and right margins to 0.9
> > > > > Set the page orientation to landscape.

> > > > > Can anyone provide a code snippet to do the above?

> > > > > Cheers

> > > > > Paul

Re:Setting Page Adjustment, Page Orientation and Margins Of An Excel Workbook from Excel


Thanks John!

Quote
"John Hill" <j...@jbeh.com> wrote in message news:3c956890_1@dnews...
> Suggest you try

> PageSetup.PaperSize := XLPaperA4;

> and while I'm at it I've found the way to set "orientation"

> PageSetup.Orientation := xlLandscape;

> All these variables can be easily found in the Excel Visual Basic Help
file
> in Excel 2000

> John

> "Paul Saxton" <psax...@onetel.net.uk> wrote in message
> news:3c951edb$1_2@dnews...
> > Thanks for clearing that up John!

> > That all works now, one more question though what is the value for A4
> paper
> > when setting the paper size?

> > Cheers

> > Paul

> > "John Hill" <j...@jbeh.com> wrote in message news:3c9501b0_1@dnews...
> > > Paul - You have misunderstood the parameters of my procedure - The
> > newsgroup
> > > wordwrap doesn't help.

> > > TMargin is my abbreviation for the "top" margin parameter that I am
> > passing
> > > into the procedure.

> > > So the call is something like.

> > > SetPagePrintMargins (MyExcelApp,  MyChart,  0.75,  1.15  ,0.75
> ,0.67  );

> > > The *numbers* are the left , right , bottom and top margin values
> > (expressed
> > > in inches) respectively - here the top margin ( tMargin)  then has the
> > value
> > > 0.67.

> > > So for your example I'd call something like.

> > > SetPagePrintMargins (MyExcelApp,  MyChart,  0.9,  0.9  ,1.0  ,1.0  );

> > > (assuming you are working in inches)

> > > "Paul Saxton" <psax...@onetel.net.uk> wrote in message
> > > news:3c945db7$1_1@dnews...
> > > > Hi John!

> > > > What unit is TMargin declared in?  I am using Excel 2000 with Delphi
> 5.
> > > > Also, any chance of seeing the code that creates the margins?

> > > > Cheers

> > > > Paul

> > > > "John Hill" <j...@jbeh.com> wrote in message

news:3c943f4d_1@dnews...

- Show quoted text -

Quote
> > > > > This doesn't answer the whole question but the following snippet
> does
> > > deal
> > > > > with margins.

> > > > > procedure SetPagePrintMargins(XLApp: TExcelApplication; XLChart:
> > > > > TExcelChart; LMargin, RMargin, BMartin, TMargin:
> > > > >   Single);
> > > > > begin
> > > > >   with xlchart.pagesetup do
> > > > >     begin
> > > > >       LeftMargin := xlapp.InchesToPoints(LMargin, lcid);
> > > > >       RightMargin := xlapp.InchesToPoints(RMargin, lcid);
> > > > >       BottomMargin := xlapp.InchesToPoints(BMartin, lcid);
> > > > >       TopMargin := xlapp.InchesToPoints(TMargin, lcid);
> > > > >     end;
> > > > > end;

> > > > > "Paul Saxton" <psax...@onetel.net.uk> wrote in message
> > > > > news:3c93ef84$1_2@dnews...
> > > > > > Hello!

> > > > > > I need to do the following to an Excel workbook through Delphi.

> > > > > > Set the page adjustment level to 87%
> > > > > > Set the top and bottom margins to 1
> > > > > > Set the left and right margins to 0.9
> > > > > > Set the page orientation to landscape.

> > > > > > Can anyone provide a code snippet to do the above?

> > > > > > Cheers

> > > > > > Paul

Other Threads