Estimados
alguien abra hecho para xbrowse la exportacion a csv como el toexcel
ya que he visto que el exportacion es mucho mas rapido que excel
METHOD SetoDbf( oDbf, aCols, lAutoSort, lAutoCols, aRows )
METHOD ToCsv( cFile, bProgress, aCols )
METHOD ToCsv( cFile, bProgress, aCols ) CLASS TXBrowse
local nKeyNo := ::KeyNo
local nRowPos := ::nRowSel
local n, uVal := "", c, oCol, nCols
local nSelect, nInd := 0, nHandle, cPic, nDec, i, cType
if ::nLen < 1
return nil
endif
//DEFAULT cFile := cNewFileName( ViewUsu():cPathTmp + "\TEMPO", "CSV" )
cFile := ".\archivo.CSV"
if (nHandle := FCREATE( cFile, 0 )) == -1
MsgInfo( "Error al crear el archivo csv","Usuario" )
return nil
endif
if aCols == nil
aCols := ::GetVisibleCols()
endif
::GoTop()
nCols := Len( aCols )
for each oCol in aCols
uVal += ";" + StrTran(cValtochar(oCol:cHeader), CRLF, " " )
next
uVal := subst( uVal, 2 ) + CRLF
nSelect := Select()
if bProgress == nil
if ::oWnd:oMsgBar == nil
bProgress := { || nil }
else
bProgress := { | n, t | ::oWnd:SetMsg( FWString( "To csv" ) + " : " + ;
Ltrim( Str( n ) ) + "/" + Ltrim( Str( t ) ) ), .t. }
endif
endif
REPEAT
for n := 1 to nCols
cType := valtype(aCols[n]:value)
do case
case cType = "N"
cPic := "9999999999"
nDec := CuantosDecimales(aCols[n]:value )
if nDec > 0
cPic += ","
for i:= 1 to nDec
cPic += "9"
next i
endif
uVal += iif( n=1, "", ";" )+strtran(ltrim(str(aCols[n]:value,12,nDec )), ".", ",")
case cType = "D"
uVal += iif( n=1, "", ";" )+dtoc(aCols[n]:Value)
case cType = "L"
uVal += iif( n=1, "", ";" )+iif( aCols[n]:Value, "SI", "NO" )
otherwise
uVal += iif( n=1, "", ";" )+strtran(cValtochar(aCols[ n ]:Value), ";","" )
endcase
next
uVal += CRLF
if !Eval( bProgress, ++nInd, ::nLen )
exit
endif
UNTIL ::Skip( 1 ) == 0
::KeyNo := nKeyNo
::nRowSel := nRowPos
::Refresh()
::SetFocus()
FWRITE( nHandle, uVal )
FCLOSE( nHandle )
//MsgInfo( "Fue creado el archivo en temporal, debera guardarlo.."+CRLF+"proceder abrir el archivo","Usuario" )
ShellExecute( WinMain():hWnd, "open", cFile )
return nil
FUNCTION CuantosDecimales(tn )
LOCAL ln := 0
DO WHILE ln <=2
IF INT(tn * 10 ^ ln) = tn * 10 ^ ln
EXIT
ENDIF
ln ++
ENDDO
RETURN ln
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: No registered users and 38 guests