Jump to content
Fivewin Brasil

Excel no RPreview com PRINT oPrn


oribeiro

Recommended Posts

João,

No exemplo citado no link eles criam uma função que exporta para o excel o conteúdo de uma matriz mas não faz a exportação do excel dos dados que estão no relatório como ele faz automaticamente com o REPORT.PRG.

O exemplo que eles usam é esse:

#include "fivewin.ch"

//----------------------------------------------------------------------------//

function Main()

   local oPrn, oFont, n, nRow
   local aData := { ;
      { "One",    "Two",      "Three"  }, ;
      { "Four",   "Five",     "Six"    }, ;
      { "Seven",  "Eight",    "Nine"   }, ;
      { "Ten",    "Eleven",   "Twelve" } }


   PRINT oPrn PREVIEW

   DEFINE FONT oFont NAME "ARIAL" SIZE 0,-15 OF oPrn
   oPrn:bToExcel  := { || ToExcel( aData ) }

   PAGE

      n     := 1
      nRow  := 1000

      do while n <= Len( aData )

         @ nRow, 1000 PRINT TO oPrn TEXT aData[ n, 1 ] FONT oFont
         @ nRow, 2000 PRINT TO oPrn TEXT aData[ n, 2 ] FONT oFont
         @ nRow, 3000 PRINT TO oPrn TEXT aData[ n, 3 ] FONT oFont

         nRow  += 200
         n++
      enddo
   ENDPAGE
   ENDPRINT

   RELEASE FONT oFont

return nil

//----------------------------------------------------------------------------//

static function ToExcel( aData )

   local oExcel   := ExcelObj()
   local oBook    := oExcel:WorkBooks:Add()
   local oSheet   := oBook:ActiveSheet
   local oRange, n

   oExcel:ScreenUpdating   := .f.
   oRange   := oSheet:Range( oSheet:Columns( 1 ), oSheet:Columns( 3 ) )
   for n := 1 to Len( aData )
      oRange:Rows( n ):Value  := aData[ n ]
   next

   oExcel:ScreenUpdating   := .t.
   oExcel:Visible          := .t.
   ShowWindow( oExcel:hWnd, 3 )

return nil

//----------------------------------------------------------------------------//

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...