jfaguiar Posted May 28, 2017 Report Share Posted May 28, 2017 Boa noite amigos. Estou tentando importar uma planilha de excel gerada por um tal de Totvs rsrs e dar um erro quando chega no campo de formato data 99/99/99 00:00:00. Tentei tratar com CTOD() mas ele não aceita o tipo que aparece como T de time. Existe alguma forma de tratar esse tipo de dados e transformar em data? Obrigado pessoal Boa Noite Quote Link to comment Share on other sites More sharing options...
Theotokos Posted May 28, 2017 Report Share Posted May 28, 2017 Se o campo estiver como caracter para vc, pegue apenas a data.... CtoD( Substr( CAMPO_DT_EXCEL, 1, 8 ) ) Quote Link to comment Share on other sites More sharing options...
rubensma Posted May 29, 2017 Report Share Posted May 29, 2017 Uso assim para testar os dados, funciona bem. Espero que ajude function gerarlote(vTot,oMeter,oText,nOption,numlote) LOCAL oExcel, oHoja dbSelectArea( "con" ) // seleciona arquivo contábil con->( dbGoTop() ) vNomenum := "Lote_"+"&numlote."+".txt" // usando macro precisa por ponto if nOption = 2 // foi selecionado arquivo texto copy to &vNomenum delimited // separado por virgula WinExec("Notepad &vNomenum",1) // 1 = diretorio corrente return nil endif nRow := 1 // reinicia a linha da planilha nCount := 0 // Zerar o total do meter oExcel := TOleAuto():New( "Excel.Application" ) oExcel:WorkBooks:Add() oHoja := oExcel:Get( "ActiveSheet" ) *::: Seleciona a guia BOLETINS para preenchimento oExcel:Sheets("Plan1"):Name := "Boletins" // nomear a 1ª guia oExcel:Sheets("Boletins"):Select() // selecionar a guia nomeada oMeter:cCaption := "Lote dos Boletins" oHoja := oExcel:Get( "ActiveSheet" ) FOR nCol := 1 TO FCOUNT() // percorrer todas as colunas oHoja:Cells( nRow, nCol ):Value := FieldName( nCol ) // linhadegrade(oHoja,nRow,nCol) NEXT DO WHILE .NOT. EOF() nRow++ 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 com valor oHoja:Cells( nRow, 4 ):NumberFormat = "###.##0,00" // Formata numerico valor oHoja:Cells( nRow, 28 ):NumberFormat = "###.##0,00" // Formata numerico oHoja:Cells( nRow, nCol ):Value := FieldGet( nCol ) else if ValType( FieldGet( nCol ) ) = "L" // se for campo lógico oHoja:Cells( nRow, nCol ):Value := FieldGet( nCol ) else oHoja:Cells( nRow, nCol ):NumberFormat = "@" // FORMATAR TEXTO oHoja:Cells( nRow, nCol ):Value := alltrim(FieldGet( nCol )) endif endif endif // linhadegrade(oHoja,nRow,nCol) NEXT oMeter:Set(++nCount) oMeter:nTotal := con->( RecCount()*1 ) oText:SetText("Exportando a Guia Boletins!"+chr(13)+; "Processando Registro : "+str(nCount,6)+"/"+str(oMeter:nTotal,6) ) con->( DBSKIP(1) ) ENDDO FOR nCol := 1 TO FCOUNT() oHoja:Columns( nCol ):AutoFit() // ajusta o tamanho das colunas NEXT cPath := CURDRIVE() + ":\" + GETCURDIR() // caminho do diretorio corrente cFilexls := cPath //+"\"+cFile vNomenum := "Lote_"+"&numlote."+".xls" // nome do arquivo a gravar cArqui := cPath + "\" + vNomenum // caminho do diretorio corrente oExcel:ActiveWorkBook:SaveAs( cArqui ) // salva como o arquivo msginfo( "O arquivo foi gerado e gravado com sucesso."+chr(13)+; "Será aberto no Excel.","Informação") cMod := "LOTE GERADO" cSer := "Foi gerado o arquivo nome: &vNomenum - Lote: &numlote" registra( cMod , cSer ) oExcel:Visible := .T. hWnd:=oExcel:hWnd ShowWindow(hWnd, 3) //3 = Maximizada, 1=Normal e 6 = Minimizada BringWindowToTop(hWnd) con->( dbZap() ) return nil Quote Link to comment Share on other sites More sharing options...
jfaguiar Posted June 5, 2017 Author Report Share Posted June 5, 2017 Se o campo estiver como caracter para vc, pegue apenas a data.... CtoD( Substr( CAMPO_DT_EXCEL, 1, 8 ) ) Entendi, mas não funciona porque o tipo de dado não retorna caractere, retorna um tipo "T". Quote Link to comment Share on other sites More sharing options...
joaosolution Posted June 5, 2017 Report Share Posted June 5, 2017 JFAguiar Boa tarde Resolvi utilizando esta função. //-------------------------- Function TtoDate( tDate ) If empty( tDate) Return( ctod("00/00/00")) Endif If ValType( tDate ) = "D" Return(tDate ) Endif Return( stod( substr( ttos( tDate ), 1, 8 ) )) Att João Bosco Theotokos 1 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.