jfaguiar Posted April 15, 2018 Report Share Posted April 15, 2018 Bom dias amigos. Estou tentando importar uma planilha para uma tabela dbf e os colunas de conteúdo data me retornam com tipo lógico ".T." Alguém sabe como resolver isso? Obrigado Para maior clareza segue parte do código: cXlsArquivo := "M:\MSYSTEMS\D_LOTFAC.XLSX" aBOLAS := { } oExcel := TOleAuto():New( "Excel.Application" ) oExcel:Workbooks:Open(cXlsArquivo) oFolha := oExcel:Get( "ActiveSheet" ) nTotRow:= oFolha:UsedRange:Rows:Count() FOR n := 6 TO nTotRow dDATA := oExcel:Cells(n,2):Value ? dDATA ? VALTYPE(dDATA) Quote Link to comment Share on other sites More sharing options...
sistem Posted April 15, 2018 Report Share Posted April 15, 2018 o que vc tem na celula oExcel:Cells(n,2):Value do excel? uma "data" em formato caracter? uma data em formato data? uq? Quote Link to comment Share on other sites More sharing options...
rubensma Posted April 15, 2018 Report Share Posted April 15, 2018 Ola, Veja se ajuda, faço assim FOR nCol := 1 TO FCOUNT() if ValType( FieldGet( nCol ) ) = "D" // se for campo data converte p/string oHoja:Cells( nRow, nCol ):Value := dtoc(FieldGet( nCol )) else if ValType( FieldGet( nCol ) ) = "N" // se for campo numérico oHoja:Cells( nRow, 7 ):NumberFormat = "###.##0,00" // FORMATAR numerico else oHoja:Cells( nRow, nCol ):NumberFormat = "@" // FORMATAR TEXTO endif oHoja:Cells( nRow, nCol ):Value := FieldGet( nCol ) // OUTRO FORMATO endif NEXT Quote Link to comment Share on other sites More sharing options...
jfaguiar Posted April 15, 2018 Author Report Share Posted April 15, 2018 Ola, Veja se ajuda, faço assim FOR nCol := 1 TO FCOUNT() if ValType( FieldGet( nCol ) ) = "D" // se for campo data converte p/string oHoja:Cells( nRow, nCol ):Value := dtoc(FieldGet( nCol )) else if ValType( FieldGet( nCol ) ) = "N" // se for campo numérico oHoja:Cells( nRow, 7 ):NumberFormat = "###.##0,00" // FORMATAR numerico else oHoja:Cells( nRow, nCol ):NumberFormat = "@" // FORMATAR TEXTO endif oHoja:Cells( nRow, nCol ):Value := FieldGet( nCol ) // OUTRO FORMATO endif NEXT Olá Rubens. Então, eu estou tentando é importar da planilha para um dbf, copiou? Quote Link to comment Share on other sites More sharing options...
jfaguiar Posted April 15, 2018 Author Report Share Posted April 15, 2018 o que vc tem na celula oExcel:Cells(n,2):Value do excel? uma "data" em formato caracter? uma data em formato data? uq? Olá. Essa célula é de formato data e ao exibí-la aparece 13/04/18 00:00:00.000. Porém ao ver o tipo com ValType() aparece .T., de modo que não posso usar CTOD() Obrigado Quote Link to comment Share on other sites More sharing options...
sistem Posted April 16, 2018 Report Share Posted April 16, 2018 uma pesquisa no forum internacional tipo: excel fecha retornou alguns links: http://forums.fivetechsupport.com/viewtopic.php?f=6&t=34449&p=204617&hilit=excel+fecha#p204617 este link acima deve resolver Quote Link to comment Share on other sites More sharing options...
rubensma Posted April 16, 2018 Report Share Posted April 16, 2018 Olá. Essa célula é de formato data e ao exibí-la aparece 13/04/18 00:00:00.000. Porém ao ver o tipo com ValType() aparece .T., de modo que não posso usar CTOD() Obrigado No meu caso a célula esta formatada no excel para "dd/mm/yy" Quote Link to comment Share on other sites More sharing options...
ADutheil Posted April 16, 2018 Report Share Posted April 16, 2018 Não tem uma coluna escondida na planilha? Quote Link to comment Share on other sites More sharing options...
cendon Posted April 16, 2018 Report Share Posted April 16, 2018 Olá, o campo de data do Excel retorna campo tipo tempo (T) com o formato dd/mm/aa hh:mm:ss você tem de trata-la como string Para converte-la tem de pegar separado a data ctod(subs([celula_excel],1,8)) Quote Link to comment Share on other sites More sharing options...
jfaguiar Posted April 16, 2018 Author Report Share Posted April 16, 2018 Olá, o campo de data do Excel retorna campo tipo tempo (T) com o formato dd/mm/aa hh:mm:ss você tem de trata-la como string Para converte-la tem de pegar separado a data ctod(subs([celula_excel],1,8)) Olá amigo. Não funciona. Qualquer comando de string como ctod(), left(), etc dar erro, porque está em formato lógico. Quanto a planilha, é aquela do site da lotofcil (D_Lotofac.Html). Fiz o download dela, descompactei, abrir-a com o excel e a salvei como planilha do excel. Quote Link to comment Share on other sites More sharing options...
rubensma Posted April 16, 2018 Report Share Posted April 16, 2018 oExcel := TOleAuto():New( "Excel.Application" ) oExcel:Workbooks:Open(cXlsArquivo) oFolha := oExcel:Get( "ActiveSheet" ) nTotRow:= oFolha:UsedRange:Rows:Count() FOR n := 6 TO nTotRow dDATA := oExcel:Cells(n,2):Value ? dDATA ? VALTYPE(dDATA) Nesse seu exemplo, não seria: dDATA := oFolha:oExcel:Cells(n,2):Value Quote Link to comment Share on other sites More sharing options...
Ladinilson Posted April 16, 2018 Report Share Posted April 16, 2018 Boa tarde, Uso esta função para ler informações data, e trato assim... IF VALTYPE(data_comp) = "T" data_comp := LEFT(TTOS(data_comp),08) data_comp := RIGHT(data_comp,2)+"/"+SUBST(data_comp,5,2)+"/"+LEFT(data_comp,4) data_comp := CTOD(data_comp) ENDIF IF VALTYPE(data_comp) != "D" data_comp := CTOD(data_comp) ENDIF Veja se funciona para vc meu caro. jfaguiar 1 Quote Link to comment Share on other sites More sharing options...
cendon Posted April 17, 2018 Report Share Posted April 17, 2018 faço assim e funciona com type=T x1=ADADOS[I,04] IF type("x1")#"U" if type("x1")="T" x1=subs(dtoc(x1),1,10) ---------------> pega a data com formato dd/mm/aaaa endif if type("x1")="N" repl dCRIACAO with str(x1,10) else repl dCRIACAO with x1 ENDIF endif move a célula antes para uma variável de memoria, depois testa Quote Link to comment Share on other sites More sharing options...
ADutheil Posted April 18, 2018 Report Share Posted April 18, 2018 oExcel := TOleAuto():New( "Excel.Application" ) oExcel:Workbooks:Open(cXlsArquivo) oFolha := oExcel:Get( "ActiveSheet" ) nTotRow:= oFolha:UsedRange:Rows:Count() FOR n := 6 TO nTotRow dDATA := oExcel:Cells(n,2):Value ? dDATA ? VALTYPE(dDATA) Tente com dDATA := oFolha:Cells(n,2):Value 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.