Array TO XLS ?

Array TO XLS ?

Postby Ariel » Wed Apr 15, 2020 8:18 pm

hola,

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

Gracias!
Ariel
 
Posts: 376
Joined: Wed Nov 29, 2006 1:51 pm
Location: Rosario - Argentina

Re: Array TO XLS ?

Postby nageswaragunupudi » Thu Apr 16, 2020 1:02 pm

A) If the DBF is already open.

Code: Select all  Expand view  RUN

(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  Expand view  RUN

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
User avatar
nageswaragunupudi
 
Posts: 10663
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Array TO XLS ?

Postby Ariel » Thu Apr 16, 2020 8:50 pm

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.
Ariel
 
Posts: 376
Joined: Wed Nov 29, 2006 1:51 pm
Location: Rosario - Argentina

Re: Array TO XLS ?

Postby nageswaragunupudi » Fri Apr 17, 2020 1:30 pm

Please try any of these two functions:
Code: Select all  Expand view  RUN
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
User avatar
nageswaragunupudi
 
Posts: 10663
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 80 guests