Page 1 of 1

Excel Question

Posted: Sun Feb 25, 2007 2:41 pm
by Jeff Barnes
Hi Everybody,

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


Thanks,

Jeff

Re: Excel Question

Posted: Sun Feb 25, 2007 3:31 pm
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

Posted: Sun Feb 25, 2007 3:42 pm
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

Posted: Sun Feb 25, 2007 3:50 pm
by Enrico Maria Giordano
Jeff Barnes wrote:What does the xlPageBreakNone do?
It removes the page break, what else? :-)

EMG

Posted: Sun Feb 25, 2007 11:24 pm
by Jeff Barnes
I figured that out as soon as I hit the send button :wink:

Thanks Enrico.



Jeff

Posted: Mon Feb 26, 2007 3:21 pm
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