Theotokos Posted April 12, 2014 Report Share Posted April 12, 2014 Bom Dia a todos! Preciso ler um arquivo excel (xml) e transferir seus dados para um DBF via programação; Alguem sabe como fazer ou por onde começar? Desde já meu muito obgdo, e desculpa é meio urgente então que puder me enviar algo no email: rone@rl-informatica.net Vlw!!! Em Cristo e amor de Maria... Quote Link to comment Share on other sites More sharing options...
crisvam Posted April 13, 2014 Report Share Posted April 13, 2014 theotokos, essa rotina faz isto que você precisa se entendi bem. Abre_Atualiza(.T.) // verifica se os arquivos que preciso estão abertos DbSelectArea("Leitrans"); Leitrans->(DbGotop() ) cArq := cGetFile32("*.XLS","Escolha o arquivo") If !File(cArq) Return Endif //-> Aqui leio os dados da planilha MsgRun("Gerando os dados, aguarde por favor ...!","Win_Sigo: Informa",; {|| LeExcel( cArq,@mIbpt, 7, {1,2,3,4,5,6},1,2,,.f. )} ) ******************************************************************************** FOR I := 1 TO Len( mIbpt ) Leitrans->(DbAppend() ) If !NetErr() // MsgInfo(mIbpt[i,2]) Leitrans->Ncmi := Str(mIbpt[i,1],8,0) Leitrans->Tipi:=If(Empty(mIbpt[i,2]),Space(1),Str(mIbpt[i,2],1,0) ) Leitrans->Orig:=If(Empty(mIbpt[i,3]),Space(1),Str(mIbpt[i,3],1,0) ) Leitrans->Pnac := Val(mIbpt[i,5]) Leitrans->Pimp := Val(mIbpt[i,6]) Else MsgStop("Desculpe_me, não foi possivel atualizar o arquivo",; "Win_Sigo: Informa") Endif Next I LeiTrans->(Dbunlock() ) MsgInfo("OK, a planilha foi transferida com sucesso","Win_Sigo: Informa") ******************************************************************************** Return // Fim do proc Atualiza_Ibpt() ******************************************************************************** mlbpt é uma matriz que recebe os dados da planilha Leitrans é o alias do arquivo que quero preencher com os dados da planilha Quote Link to comment Share on other sites More sharing options...
Theotokos Posted April 14, 2014 Author Report Share Posted April 14, 2014 Vlw !!! faltou o LeExcel, que deve ser a rotina que jogas os dados para o array... se puder posta para nós... obrigado!!! Quote Link to comment Share on other sites More sharing options...
Jmsilva Posted April 14, 2014 Report Share Posted April 14, 2014 http://fivewin.com.br/index.php?/topic/21758-gerar-planilha-no-openoffice/ nesta classe faltou o getString(), para pegar o valor da célula......só implementar.... Quote Link to comment Share on other sites More sharing options...
crisvam Posted April 14, 2014 Report Share Posted April 14, 2014 Desculpe-me Theotokos: Veja abaixo: Function LeExcel(cXlsArquivo,aVetor,nColunas,aColunas,nColObrig,nLinhaInicial,; aTitulos,aColAd,cSheets) Local oDlg,oExcel,oFolha,nLinhas Local cProject, cFile, cRota:=cFILEPATH(GETMODULEFILENAME(GETINSTANCE())) ******************************************************************************** // Tirei as 02 linhas abaixo pois não tem necessidade //cXlsArquivo+='.xls' //cXlsArquivo:=strtran( cXlsArquivo, '.xls.xls','.xls' ) If !file( cXlsArquivo ) msgalert( 'Arquivo '+cXlsArquivo+' não encontrado.', 'Verifique' ) Else oExcel := TOleAuto():New( "Excel.Application" ) //oExcel:Workbooks:Open(cRota+cXlsArquivo) oExcel:Workbooks:Open(cXlsArquivo) oFolha := oExcel:Get( "ActiveSheet" ) oWork := oExcel:Get( "ActiveWorkbook" ) oWork:Saved:=.t. nLinhas:=oFolha:UsedRange:Rows:Count() oExcel:Workbooks:Close() oExcel:Quit() LeArqExcel( cXlsArquivo,nColunas, aColunas,@aVetor, nColObrig,nLinhaInicial,aTitulos,aColAd,cSheets ) Endif ******************************************************************************** Return aVetor ******************************************************************************** Function LeArqExcel( cXlsArquivo, nColunas, aColunas, aVetor, nColObrig,; nLinhaInicial,aTitulos,aColAd,cSheets ) Local aLinha Local cNome, cMatricula, cChave, cLinha Local nLinhas, x, x1, nPos Local oExcel, oFolha, oWork Local xLinha,nCol:=1,nDados:=0,nH,nSheets:=0,nF Local nT,nP,nColAd,lColAd,nContaAba:=1 //-> geraldo ******************************************************************************** DEFAULT nColObrig:=aColunas[1] DEFAULT nLinhaInicial := 1 DEFAULT cSheets := .f. oExcel := TOleAuto():New( "Excel.Application" ) oExcel:Workbooks:Open(cXlsArquivo) //-> Verifica abas nSheets := oExcel:Sheets:Count() //-> Verifica se vai ler cabeçalho apenas da primeira planilha If cSheets = .f. nLerAba := 1 Else nLerAba := nSheets Endif For nF := 1 to nSheets oExcel:Worksheets( nF ):Select() oFolha := oExcel:Get( "ActiveSheet" ) oWork := oExcel:Get( "ActiveWorkbook" ) oWork:Saved:=.t. //-> Inclui essas linha para pegar cabeçalho (Geraldo 10/11/2009) If nContaAba <= nLerAba If !empty(aColAd) nColAd := Len(aColAd) For nT = 1 to nColAd aAdd( aTitulos, {oFolha:Cells( aColAd[nT,1],aColAd[nT,2] ):Value } ) Next /* Como pegar os dados do cabeçalho For nP = 1 to Len(aTitulos) ? aTitulos[nP,1] Nex */ Endif nContaAba++ Endif nLinhas=oFolha:UsedRange:Rows:Count() For x:= nLinhaInicial to nLinhas xLinha:=oFolha:Cells( x, nColObrig ):Value If nColObrig > 0 .and. xLinha == nil loop Endif aLinha:={} For x1 = 1 to nColunas If ascan( aColunas, x1 )>0 aadd( aLinha, oFolha:Cells( x, x1 ):Value ) Endif Next x1 aAdd( aVetor, aLinha ) Next x Next oExcel:Workbooks:Close() oExcel:Quit() ******************************************************************************** Return( aVetor ) ******************************************************************************** OBS.: Parte destas funções não são minhas, mas como não me lembro de onde tirei, desde já, peço desculpa pelo esquecimento Theotokos 1 Quote Link to comment Share on other sites More sharing options...
Theotokos Posted April 14, 2014 Author Report Share Posted April 14, 2014 Valeu Crisvam, muito obrigado a sua rotina deu certo!!! Quote Link to comment Share on other sites More sharing options...
syspel Posted April 19, 2017 Report Share Posted April 19, 2017 vou testar ja agradeco obrigado Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.