Array TO XLS ?

Post Reply
Ariel
Posts: 309
Joined: Wed Nov 29, 2006 1:51 pm
Location: Rosario - Argentina

Array TO XLS ?

Post by Ariel »

hola,

existe una funcion como FW_CopyDBF2XL(), pero para ArrayToXLS() ?

Gracias!
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Array TO XLS ?

Post by nageswaragunupudi »

A) If the DBF is already open.

Code: Select all

(cAlias)->( FW_DbfToExcel( [cFieldList], [bFor], [bWhile], [nNext], [nRec], [lRest], [cSaveToFileName] )
 
Parameters:
1. cFieldList (Optional): Can be a commadelimited list of fileds. Eg:"FIRST,CITY,AGE"
Default all fields.
2 to 6. bFor,bWhile,nNext,nRec,lRest: (Optional) Same functionality as in DBEVAL()

7. cFileName (Optional)
If nil, data is exported to Excel and displayed. Returns the active sheet (oSheet).
The user can do further work on the open sheet or programmer can do further work using the oSheet object before saving or discarding.

If a file name is specified with extension of xlsx, pdf or htm/html, the data is saved to excel/pdf/html file,

B) Without opening the DBF or when the DBF is opened in shared mode.

Code: Select all

FW_CopyDBFTO( [cDestXLS], [cSourceDBF] )
 
Parameters:
cDestXLS: Can be nil or a file name with extension xlsx,pdf,html. Same as parameter 7 in the first function.
cSourceDBF: Defaults to the file name of the current Alias.

This function exports the entire DBF, including deleted records.
Regards

G. N. Rao.
Hyderabad, India
Ariel
Posts: 309
Joined: Wed Nov 29, 2006 1:51 pm
Location: Rosario - Argentina

Re: Array TO XLS ?

Post by Ariel »

Mr Rao,

gracias por contestar pero NO quiero pasar una dbf sino un ARRAY a Xls, preguntaba si habia alguna funcion parecida a esa para hacerlo.

Saludos.
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Array TO XLS ?

Post by nageswaragunupudi »

Please try any of these two functions:

Code: Select all

function ArrayToExcel( aData )

   local oExcel, oBook, oSheet
   local nRow, nCol, nCols := 1

   if ( oExcel := ExcelObj() ) == nil
      ? "Excel not instqalled"
   else
      oBook    := oExcel:WorkBooks:Add()
      oSheet   := oBook:ActiveSheet
      oExcel:ScreenUpdating := .f.

      for nRow := 1 to Len( aData )
         if ValType( aData[ nRow ] ) == "A"
            nCols := Max( nCols, Len( aData[ nRow ] ) )
            for nCol := 1 to Len( aData[ nRow ] )
               oSheet:Cells( nRow, nCol ):Value := aData[ nRow, nCol ]
            next
         else
            oSheet:Cells( nRow, 1 ):Value := aData[ nRow ]
         endif
      next

      oSheet:Range( oSheet:Columns( 1 ), oSheet:Columns( nCols ) ):AutoFit()
      oExcel:ScreenUpdating := .t.
      oExcel:visible := .t.
   endif

return nil


function ArrayToExcel2( aData )

   local oExcel, oBook, oSheet
   local cText, oClp, nCols := 0

   if ( oExcel := ExcelObj() ) == nil
      ? "Excel not instqalled"
   else
      oBook    := oExcel:WorkBooks:Add()
      oSheet   := oBook:ActiveSheet
      oExcel:ScreenUpdating := .f.

      aData    := AClone( aData )
      AEval( aData, { |a| nCols := Max( nCols, Len( a ) ) } )
      AEval( aData, { |a,i| aData[ i ] := FW_ArrayAsList( a, Chr( 9 ) ) } )
      cText    := FW_ArrayAsList( aData, CRLF )

      oClp     := TClipboard():New()
      oClp:SetText( cText )
      oSheet:Cells( 1, 1 ):Select()
      oSheet:Paste()
      oClp:Clear()
      oClp:End()

      oSheet:Range( oSheet:Columns( 1 ), oSheet:Columns( nCols ) ):AutoFit()

      oExcel:ScreenUpdating := .t.
      oExcel:visible := .t.
   endif

return nil

 
Regards

G. N. Rao.
Hyderabad, India
Post Reply