Page 1 of 1

TWBrowse: Print report with selected columns in browse.

Posted: Fri Apr 18, 2008 3:39 am
by Rochinha
Friends,

This little code make a big result.

Code: Select all

        ...
        oLbx:bRClicked := {| nRow, nCol | ;
                Reporte( oLbx, "Title", .t., "Subtitle", ;  
                { "0","0","C","C","D","N","N","0","0" } ) } // Columns Flageds
        ...
"0" - Hide column in report
"C" - Shown character content
"D" - Shown data character
"N" - Shown numeric character

The implement:

Code: Select all

function Reporte( oRPTLbx, cTitle, lPreview, cTitle2, aQColunas, cdblFilter )
   local oRpt
   local nRecNo := If( Upper( oRPTLbx:cAlias ) != "ARRAY", ( oRPTLbx:cAlias )->( RecNo() ), 0 )
   local aData  := Eval( oRPTLbx:bLine )
   local n
   local nCharWidth
   local oRPTFont1, oRPTFont2, oRPTFont3
   public nCreditos := 0
   public nDebitos  := 0
   nCharWidth := GetTextWidth( 0, "B", If( oRPTLbx:oFont != nil, oRPTLbx:oFont:hFont, 0 ))
   DEFAULT cTitle := oRPTLbx:oWnd:cTitle, lPreview := .t., cdblFilter := {||.t.}
   DEFINE PEN oPen1 WIDTH 1 COLOR nRGB(238,238,238)
   DEFINE FONT oRPTFont1 NAME "ARIAL" SIZE 0,-8
   DEFINE FONT oRPTFont2 NAME "ARIAL" SIZE 0,-8 BOLD
   DEFINE FONT oRPTFont3 NAME "ARIAL" SIZE 0,-20 BOLD
   if lPreview
      REPORT oRpt TITLE CL_Nome, cTitle, cTitle2 PREVIEW ;
             FOOTER CL_Endereco CENTER FONT oRPTFont1, oRPTFont2, oRPTFont3 // Str( oRpt:nPage, 3 )
   else
      REPORT oRpt TITLE CL_Nome, cTitle, cTitle2 ;
             FOOTER CL_Endereco CENTER FONT oRPTFont1, oRPTFont2, oRPTFont3 // Str( oRpt:nPage, 3 )
   endif
   if Empty( oRpt ) .or. oRpt:oDevice:hDC == 0
      return nil
   else
      Eval( oRPTLbx:bGoTop )
   endif
   if oRPTLbx:aColSizes == nil
      oRPTLbx:aColSizes = Array( Len( aData ) )
      for n = 1 to Len( aData )
          oRPTLbx:aColSizes[ n ] = 80
      next
   else
      if Len( oRPTLbx:aColSizes ) < Len( aData )
         n = Len( oRPTLbx:aColSizes )
         do while n++ < Len( aData )
            AAdd( oRPTLbx:aColSizes, 80 )
         end
      endif
   endif
   for n = 1 to Len( aData )
       if aQColunas <> nil
          if aQColunas[ n ] = "0"
             loop
          else
             if aQColunas[ n ] = "N"
                RptAddColumn({ GenLocal( oRPTLbx:aHeaders, n ) },,;
                          { GenBlock( oRPTLbx:bLine, n ) },;
                          Int( oRPTLbx:aColSizes[ n ] / nCharWidth ),{"@9"},{||2},.T.,,UPPER("RIGHT"),.F.,.T., )
             else
                RptAddColumn({ GenLocal( oRPTLbx:aHeaders, n ) },,;
                          { GenBlock( oRPTLbx:bLine, n ) },;
                          Int( oRPTLbx:aColSizes[ n ] / nCharWidth ),{"@!"},{||2},.F.,,UPPER("LEFT") ,.F.,.T., )
             endif
          endif
       else
          if ValType( aData[ n ] ) != "N"
             if IsNumeric( aData[ n ] )
                RptAddColumn({ GenLocal( oRPTLbx:aHeaders, n ) },,;                                 
                          { GenBlock( oRPTLbx:bLine, n ) },;
                          Int( oRPTLbx:aColSizes[ n ] / nCharWidth ),{"@9"},{||2},.F.,,UPPER("RIGHT"),.F.,.T., )
             else
                RptAddColumn({ GenLocal( oRPTLbx:aHeaders, n ) },,;
                          { GenBlock( oRPTLbx:bLine, n ) },;
                          Int( oRPTLbx:aColSizes[ n ] / nCharWidth ),{"@!"},{||2},.F.,,UPPER("LEFT") ,.F.,.T., )
             endif
          else
             RptAddColumn({ GenLocal( oRPTLbx:aHeaders, n ) },,;
                          { GenBlock( oRPTLbx:bLine, n ) },;
                          Int( oRPTLbx:aColSizes[ n ] / nCharWidth ),{"@E 999,999.99"},{||2},.T.,,UPPER("RIGHT"),.F.,.T., )
          endif
       endif
   next
   ENDREPORT
   //oRpt:oDevice:SetLandScape()
   //oRpt:CellView()
   oRpt:bSkip = { || oRpt:Cargo := oRPTLbx:Skip( 1 ) }
   oRpt:Cargo = 1
   /* First line of title bold */
   oRpt:oTitle:aFont[1]:= {|| 3 }
   oRpt:oTitle:aFont[2]:= {|| 2 }
   oRpt:oTitle:aFont[3]:= {|| 1 }
   ACTIVATE REPORT oRpt ; // ON END ReporteTotal(oRpt) ;
      FOR Eval( cdblFilter ) ;
      WHILE If( Upper( oRPTLbx:cAlias ) == "ARRAY",;
                oRpt:nCounter < Eval( oRPTLbx:bLogicLen ),;
                oRpt:Cargo == 1 )
   if Upper( oRPTLbx:cAlias ) != "ARRAY"
      ( oRPTLbx:cAlias )->( DbGoTo( nRecNo ) )
   endif
   oRPTLbx:Refresh()
   oRPTFont1:End()
   oRPTFont2:End()
   oRPTFont3:End()
   return nil

Posted: Fri Apr 18, 2008 5:32 am
by nageswaragunupudi
Report feature of xBrowse is a more versatile and let the user to select columns and rows to be printed. It supports European or general number formatting to be selected. Even allows grouped reports. Worth exploring its capabilities

Posted: Fri Apr 18, 2008 11:56 am
by Rochinha
Friend,

Post a little sample,

thanks.