Cotaçao Excel

Discussão em 'Progress 4GL' iniciado por Rafael, Setembro 8, 2009.

  1. Rafael

    Rafael Sem Pontuação

    Por favor preciso de uma ajuda. To gerando certo os valores do item nas linhas certas, mais a posição dos fornecedores não , ele fica repetindo nas colunas os nomes dos fornecedores isso que eu queria acertar.

    def var chExcelApplication as com-handle no-undo.
    def var chBookMark as com-handle no-undo.
    def var Workbooks as com-handle no-undo.
    def var n-linha as int.
    def var c-coluna as int.
    def var totalitem as dec.
    def var totalvalor as dec.
    def var index-col as int.

    create "Excel.Application" chExcelApplication.
    chExcelApplication:visible = true.
    chExcelApplication:ScreenUpdating = no.
    chExcelApplication:Workbooks:ADD("S:\ems\206esp\Compras\cotacao\COTACAO-ITEM.xls").
    chexcelapplicAtion:sheets:item(1).

    assign n-linha = 4
    index-col = 5.

    for each cotacao-item no-lock where
    cotacao-item.numero-ordem >= 50014100 and
    cotacao-item.numero-ordem <= 50014800
    break by cotacao-item.it-codigo
    by cotacao-item.cod-emitente:
    for each emitente no-lock where
    emitente.cod-emitente = cotacao-item.cod-emitente:

    find item of cotacao-item no-lock no-error.

    /*find emitente no-lock where
    emitente.cod-emitente = cotacao-item.cod-emitente no-error.*/

    find item of cotacao-item no-lock no-error.

    if first-of (cotacao-item.it-codigo) then do:

    assign n-linha = n-linha + 1
    chexcelapplicAtion:range("A" + string(n-linha)):value = cotacao-item.it-codigo
    chexcelapplicAtion:range("B" + string(n-linha)):value = item.desc-item.

    chexcelapplicAtion:Columns("B"):EntireColumn:AutoFit.

    end.

    if last-of (cotacao-item.cod-emitente) then do:

    assign index-col = index-col + 1
    chexcelapplicAtion:Cells(4,index-col):value = emitente.nome-abrev
    chexcelapplicAtion:Cells(n-linha,index-col):value = STRING((cotacao-item.preco-fornec),'>>,>>>,>>9.99').

    end.

    chexcelapplicAtion:Columns("F"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("G"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("H"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("I"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("J"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("K"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("L"):EntireColumn:AutoFit.

    end.
    end.
    chexcelapplicAtion:Range("A1"):select.
    chExcelApplication:ScreenUpdating = yes.
    release object chExcelApplication.

    segue em anexo a planilha gerada.
  2. Cobra.cne

    Cobra.cne Equipe de Suporte Moderador

    Rafael,

    Tenta assim, inverti o break by primeiro por fornecedor depois por item, porém não tive tempo para validar se os valores estão nos lugares corretos, mas acho que o caminho é este.

    Código:
    def var chExcelApplication as com-handle no-undo.
    def var Workbooks as com-handle no-undo.
    def var n-linha as int.
    def var c-coluna as int.
    def var totalitem as dec.
    def var totalvalor as dec.
    def var index-col as int.
    
    create "Excel.Application" chExcelApplication.
    chExcelApplication:visible = true.
    chExcelApplication:ScreenUpdating = no.
    chExcelApplication:Workbooks:ADD("C:\DESENV\CLEILTON\teste.xls").
    chexcelapplicAtion:sheets:item(1).
    
    assign n-linha = 4
    index-col = 5.
    
    for each cotacao-item no-lock where
        cotacao-item.numero-ordem >= 11081000 and 
        cotacao-item.numero-ordem <= 11081600
        break by cotacao-item.cod-emitente
              by cotacao-item.it-codigo :
    
        find item NO-LOCK
                WHERE ITEM.it-codigo = cotacao-item.it-codigo NO-ERROR.
    
        if first-of (cotacao-item.it-codigo) then do:
    
            assign n-linha = n-linha + 1
            chexcelapplicAtion:range("A" + string(n-linha)):value = cotacao-item.it-codigo
            chexcelapplicAtion:range("B" + string(n-linha)):value = item.desc-item.
    
            chexcelapplicAtion:Columns("B"):EntireColumn:AutoFit.
    
        end.
    
    
        if FIRST-OF (cotacao-item.cod-emitente) then  do:
            FIND FIRST emitente no-lock where 
                    emitente.cod-emitente = cotacao-item.cod-emitente NO-ERROR. 
            assign index-col = index-col + 1
            chexcelapplicAtion:Cells(4,index-col):value = emitente.nome-abrev.
        end.
        ASSIGN chexcelapplicAtion:Cells(n-linha,index-col):value = STRING((cotacao-item.preco-fornec),'>>,>>>,>>9.99').
    
    end.
    chexcelapplicAtion:Range("A1"):select.
    chExcelApplication:ScreenUpdating = yes.
    
    /*Salvar arquivo antes de fechar*/
    chExcelApplication:ActiveWorkbook:SaveAs ("Destino.xls",-4143,"","",FALSE,FALSE,TRUE,FALSE,FALSE).
    
    /*para fechar o excel antes do release, caso contrário ele não fecha*/
    chExcelApplication:QUIT().
    
    release object chExcelApplication.
    release object Workbooks.
    
    Qualquer coisa posta ai, assim que tiver um tempinho dou uma olhada

    T+
  3. Rafael

    Rafael Sem Pontuação

    Cara valeu pela ajuda o fornecedor funcionou belezinha, mais agora os itens repetem conforme a quantidade de fornecedor que eles foram cotados, não deu certo então. Eu fiz as alteração que vc me aconselhou segue abaixo:

    def var chExcelApplication as com-handle no-undo.
    def var chBookMark as com-handle no-undo.
    def var Workbooks as com-handle no-undo.
    def var n-linha as int.
    def var c-coluna as int.
    def var totalitem as dec.
    def var totalvalor as dec.
    def var index-col as int.

    create "Excel.Application" chExcelApplication.
    chExcelApplication:visible = true.
    chExcelApplication:ScreenUpdating = no.
    chExcelApplication:Workbooks:ADD("S:\ems\206esp\Compras\cotacao\COTACAO-ITEM.xls").
    chexcelapplicAtion:sheets:item(1).

    assign n-linha = 4
    index-col = 5.

    for each cotacao-item no-lock where
    cotacao-item.numero-ordem >= 50014100 and
    cotacao-item.numero-ordem <= 50014800
    break by cotacao-item.cod-emitente
    by cotacao-item.it-codigo:

    find item NO-LOCK
    WHERE ITEM.it-codigo = cotacao-item.it-codigo NO-ERROR.

    if first-of (cotacao-item.it-codigo) then do:

    assign n-linha = n-linha + 1
    chexcelapplicAtion:range("A" + string(n-linha)):value = cotacao-item.it-codigo
    chexcelapplicAtion:range("B" + string(n-linha)):value = item.desc-item.

    chexcelapplicAtion:Columns("B"):EntireColumn:AutoFit.
    end.

    if first-of (cotacao-item.cod-emitente) then do:
    FIND FIRST emitente no-lock where
    emitente.cod-emitente = cotacao-item.cod-emitente NO-ERROR.
    assign index-col = index-col + 1
    chexcelapplicAtion:Cells(4,index-col):value = emitente.nome-abrev.
    end.
    ASSIGN chexcelapplicAtion:Cells(n-linha,index-col):value = STRING((cotacao-item.preco-fornec),'>>,>>>,>>9.99').

    chexcelapplicAtion:Columns("F"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("G"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("H"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("I"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("J"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("K"):EntireColumn:AutoFit.
    chexcelapplicAtion:Columns("L"):EntireColumn:AutoFit.

    end.
    chexcelapplicAtion:Range("A1"):select.
    chExcelApplication:ScreenUpdating = yes.
    release object chExcelApplication.

Compartilhe esta Página