Jump to content
Fivewin Brasil

Ler Excel Coluna de data


jfaguiar

Recommended Posts

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)
 

 

 

Link to comment
Share on other sites

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
 

Link to comment
Share on other sites

 

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?

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

 

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.

 

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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.

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...