Importar uma planilha de excel para uma tabela no progress

Discussão em 'Progress 4GL' iniciado por Ricardo321210, Março 30, 2010.

  1. Ricardo321210

    Ricardo321210 Sem Pontuação

    Boa Tarde, pessoal como faço para importar uma planilha de excel para uma tabela no progress?

    São somente dois campos (código e descrição).

    Obrigado,
  2. LeandroSantos

    LeandroSantos Membro Participativo

  3. jonas

    jonas Membro Participativo

    Segue um exemplo:

    Código:
      define variable cArquivo           as char no-undo.
      define variable lOk                as logical no-undo.
      define variable chExcelApplication as com-handle.
      define variable chWorkbook         as com-handle.
      define variable chWorkSheet        as com-handle.
      define variable cEstabel           as char no-undo.
      define variable cCelula            as char no-undo.
      define variable iLinha             as int no-undo initial 1.
      define variable lProcessa          as log no-undo.
      define variable i-Cont             as int no-undo initial 0. 
      define variable c-Aliq             as char no-undo initial ''.
      def var cTeste as char no-undo.
    
      define temp-table tt-aux no-undo
          field tt-cod-estabel as char
          field tt-desc-pro    as char
          field tt-it-codigo   as char
          field tt-clas-fisc   as char
          field tt-aliq-ipi    as dec.
    
      assign cArquivo = "c:\datasul\ems204\spool\teste.xlsx".
      
      create "Excel.Application"  chExcelApplication.
      assign chWorkbook = chExcelApplication:workBooks:open(cArquivo).
      assign chWorkSheet = chExcelApplication:Sheets:Item(1).
      iLinha = 1.
    
      /* importa as informacoes das planilhas */
      repeat:
          assign ilinha = iLinha + 1.
            
          if lOk then do:
              chWorkbook:close(true).
              chExcelApplication:quit().
              release object chExcelApplication.
              release object chWorkbook.
              release object chWorkSheet.
              return "NOK".
          end.
    
          assign i-cont = i-cont + 1.
    
          create tt-aux.
          
          assign cCelula = 'A' + string(iLinha,"99999").
          assign tt-aux.tt-it-codigo = string(chWorkSheet:Range(cCelula):value).
    
          assign cCelula = 'B' + string(iLinha,"99999").
          assign tt-aux.tt-desc-pro = chWorkSheet:Range(cCelula):value.
    
          
          if iLinha > 1000  /* quantidade de linhas da planilha */ then do:
              leave.
              return "OK".
          end.
      end.
    
      chWorkbook:close(true).
      chExcelApplication:quit().
      release object chExcelApplication.
      release object chWorkbook.
      release object chWorkSheet.
    
      for each tt-aux.
    
          /* criar/alterar os registros na sua tabela */
          
      end.
    
    

Compartilhe esta Página