Excel Question

Post Reply
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Excel Question

Post by Jeff Barnes »

Hi Everybody,

Does anyone know how to force a "Page Break" in Excel via FW ?


Thanks,

Jeff
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Excel Question

Post by Enrico Maria Giordano »

This is a working sample:

Code: Select all

#define xlPageBreakManual -4135
#define xlPageBreakNone -4142


FUNCTION MAIN()

    LOCAL oExcel := CREATEOBJECT( "Excel.Application" )

    LOCAL oSheet

    oExcel:WorkBooks:Add()

    oSheet = oExcel:ActiveSheet

    oSheet:Cells( 1, 1 ):Value = "This is the first page"

    oSheet:Rows( 2 ):PageBreak = xlPageBreakManual

    oSheet:Cells( 2, 1 ):Value = "This is the second page"

    oExcel:Visible = .T.

    RETURN NIL
EMG
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

Thanks Enrico

I did some more searching and also found the solution:
(similar to yours)

oSheet:Rows( nTopPage ):Set("PageBreak",-4135)

What does the xlPageBreakNone do?


Also, for anyone who is interested, I found a list of the disserent numbers associated with the excel commands (scroll down about 1/4 of the page):


http://nerds-central.blogspot.com/2007 ... hive.html


Jeff
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

Jeff Barnes wrote:What does the xlPageBreakNone do?
It removes the page break, what else? :-)

EMG
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Post by Jeff Barnes »

I figured that out as soon as I hit the send button :wink:

Thanks Enrico.



Jeff
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Post by Gale FORd »

I have found that during printing and page break preview, it resets or ignores manual page breaks.
I have found that the following code will make Excel calculate the page breaks and then override the ones you want.

Code: Select all

FUNCTION MAIN()
   LOCAL oExcel := CREATEOBJECT( "Excel.Application" )
   LOCAL oSheet
   oExcel:WorkBooks:Add()
   oSheet = oExcel:ActiveSheet
   oExcel:ActiveWindow:View := 2
  // View = 2 sets excel to page break preview mode.
   oSheet:ResetAllPageBreaks()
   nTotalBreaks := oSheet:HPageBreaks:Count()
   for nCounter := 1 to nTotalBreaks
      oPageBreak := oSheet:HPageBreaks[nCounter]                // This Works
      do case
         case nCounter = 1
            cCells := 'A'+alltrim(str(nMyFirstBreak))
         case nCounter = 2
            cCells := 'A'+alltrim(str(nMySecondBreak))
      endcase
      oPageBreak:location := oSheet:Range( cCells )
   next
return nil
Post Reply