Jump to content
Fivewin Brasil

Célula tipo data do Excel, como importar p/dbf


jfaguiar

Recommended Posts

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

Link to comment
Share on other sites

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
 

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...