In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Importar hoja de Excell

Foro público de Xailer en español
Responder
Avatar de Usuario
jasm
Mensajes: 447
Registrado: Mar Jul 08, 2008 8:12 pm

Importar hoja de Excell

Mensaje por jasm »

Necesito importar datos desde una hoja de excell al programa ¿alguien ha hecho algo de esto?

Gracias.
mcastabaron
Mensajes: 154
Registrado: Vie Mar 14, 2008 7:25 am
Ubicación: Almería

Re: Importar hoja de Excell

Mensaje por mcastabaron »

Yo lo que hago es guardar la hoja de excel como DBF 4 (dBASE IV) y ya puedes tratar los datos normalmente.
Esto si estás utilizado DBFS.
Miguel C.
Avatar de Usuario
XeviCOMAS
Mensajes: 582
Registrado: Sab Mar 12, 2011 8:16 pm

Re: Importar hoja de Excell

Mensaje por XeviCOMAS »

Jasm

Yo lo estoy utilizando... te adjunto el prg de la carga de tarifa que tengo para actualizar la tarifa de AZKOYEN, por ejemplo.

Espero te sirva.

******************************************************************************************
#include "Xailer.ch"

Static lDesplegaMenu

PROCEDURE xFrmActualitzacioArticlesAzkoyen(oSender)
local nAscan
Local aForms := Application:aForms

ProcessMessages()

If (nAscan := aScan( aForms , {|o| o:ClassName() == TFrmActualitzacioArticlesAzkoyen():ClassName() } )) = 0
If (nAscan := aScan( aForms , {|o| o:ClassName() == TFrmEmpreses():ClassName() .or. o:ClassName() == TFrmIndexar():ClassName() } )) # 0
xSortir( oSender )
Return
EndIf
Else
aForms[nAScan]:SetFocus()
Return
EndIf

lDesplegaMenu := oSender != Nil
TFrmActualitzacioArticlesAzkoyen():New( Application:oMainForm ):Show()

Return

Static Procedure xSortir(o)
If( lDesplegaMenu, xDesplegaMenu( o, 4, 6, 0 ), )
Return

CLASS TFrmActualitzacioArticlesAzkoyen FROM TForm

COMPONENT oLabel1
COMPONENT oButton1
COMPONENT oCheckbox1
COMPONENT oCbboxImporte
COMPONENT oLabel2
COMPONENT oEditBtn1
COMPONENT oFileOpenDlg1
COMPONENT oLabel3
COMPONENT oCbboxReferencia
COMPONENT oLabel4
COMPONENT oCbboxDescripcio
COMPONENT oLabel5

METHOD CreateForm()
METHOD Button1Click( oSender )
METHOD EditBtn1BtnClick( oSender, Value )
METHOD FormClose( oSender, @lClose )
METHOD FormDestroy( oSender )

ENDCLASS

#include "ActualitzacioArticlesAzkoyen.xfm"

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

METHOD FormClose( oSender, lClose ) CLASS TFrmActualitzacioArticlesAzkoyen
lClose := ::oCbboxImporte:lEnabled
RETURN Nil

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

METHOD FormDestroy( oSender ) CLASS TFrmActualitzacioArticlesAzkoyen
If( Len( Application:aForms ) = 2, xSortir( ::oParent ), )
RETURN Nil

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

METHOD EditBtn1BtnClick( oSender, Value ) CLASS TFrmActualitzacioArticlesAzkoyen
If ::oFileOpenDlg1:Run()
::oEditBtn1:cText := ::oFileOpenDlg1:cFullFileName
EndIf
RETURN Nil

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

METHOD Button1Click( oSender ) CLASS TFrmActualitzacioArticlesAzkoyen
Local oExcel, cL
Local n := If( ::oCheckbox1:lChecked, 1, 0 )
Local nTime := Seconds()
Local nNoves := 0
Local lAbort := .F.
Local cAliasArticles := "ARTICLESACTUALITZACIOARTICLESAZKOYEN"

Application:lBusy := .T.
TRY
oExcel := GetActiveObject( "Excel.Application" )
CATCH
TRY
oExcel := CreateObject( "Excel.Application" )
CATCH
MsgAlert( "ERROR! Excel not avialable. [" + Ole2TxtError()+ "]" )
oExcel := NIL
Application:lBusy := .F.
RETURN Nil
END
END

If !xDbfArticles( .F., AppData:cRuta, If( AppData:lArticles, AppData:cEmpCompartir, AppData:cCodiEmpresa ), cAliasArticles )
oExcel := NIL
Application:lBusy := .F.
RETURN Nil
EndIf

::oCheckbox1:lEnabled := ::oCbboxReferencia:lEnabled := ::oCbboxDescripcio:lEnabled := ::oCbboxImporte:lEnabled := ::oEditBtn1:lEnabled := .F.
::oButton1:OnClick := {|| lAbort := .T. }
::oButton1:cText := "Abortar"
ProcessMessages()

TRY
oExcel:WorkBooks():Open( ::oFileOpenDlg1:cFullFileName )
* oExcel:Worksheets("11111")

TRY
DELETE ALL FOR Field->CODI = " 1"
PACK

While !lAbort
n++
cL := oExcel:Range(::oCbboxReferencia:cText+AllTrim(Str(n))):Value

If Empty(cL)
MsgInfo( "Total Referències Azkoyen: "+AllTrim(Str(nNoves)) +;
" en " + AllTrim( Str( Seconds()-nTime ) ) + " seg." )
EXIT
EndIf

If n % 25 == 0
::oLabel1:cText := cL
ProcessMessages()
EndIf

(cAliasArticles)->(DbSeek(cL))
IF (cAliasArticles)->(Eof())
nNoves++
(cAliasArticles)->(DbAppend())
(cAliasArticles)->REFERENCIA:=cL
ENDIF
(cAliasArticles)->DESCRIPCIO := oExcel:Range(::oCbboxDescripcio:cText+AllTrim(Str(n))):Value
(cAliasArticles)->PC := oExcel:Range(::oCbboxImporte:cText+AllTrim(Str(n))):Value
(cAliasArticles)->CODI := " 1"
(cAliasArticles)->IVA := 1
* (cAliasArticles)->INC := 12
(cAliasArticles)->UNIT := 1
(cAliasArticles)->ENLLAC := "001"

EndDo

CATCH
MSGALERT( "S'ha produit un Error!!!" )
END

(cAliasArticles)->( DbCloseArea() )

oExcel:ActiveWorkbook:Close( .F. )
oExcel := NIL
CATCH
MSGALERT( "S'ha produit un Error!!!..." +Chr(10)+ "oExcel:WorkBooks():Open( " + ::oFileOpenDlg1:cFullFileName + ")" )
END


::oCheckbox1:lEnabled := ::oCbboxReferencia:lEnabled := ::oCbboxDescripcio:lEnabled := ::oCbboxImporte:lEnabled := ::oEditBtn1:lEnabled := .T.
::oButton1:OnClick := "Button1Click"
::oButton1:cText := "Button1"
Application:lBusy := .F.

RETURN Nil

//------------------------------------------------------------------------------
Un Saludo,
Xevi.
Avatar de Usuario
jasm
Mensajes: 447
Registrado: Mar Jul 08, 2008 8:12 pm

Re: Importar hoja de Excell

Mensaje por jasm »

Gracias Xevi.
Seguro que lo puedo adaptar.
Responder