1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Open Office da erro ambiente Grafico

Discussão em 'Outros/Diversos' iniciado por alexandretm, Junho 30, 2020.

  1. alexandretm

    alexandretm Membro Participativo

    Srs(a) boa Tarde, a agum tem estava pensando em desenvolver algo com BROffice, resolvi semana passada, procurei no grupo e encontrei exemplos, fiz modificações para atender minha necessidade, porem agora não consigo ir adiante, efetuando teste rodando pelo editor direto o programa funciona perfeito, mas quando coloco o programa gráfico para que nosso colaborador use, ele da vários erros e não imprime.
    Segue fonte

    /* Definicoes Parametros **/
    DEFINE INPUT PARAMETER p-cod-estabel LIKE ped-venda.cod-estabel NO-UNDO.
    DEFINE INPUT PARAMETER p-nome-abrev LIKE ped-venda.nome-abrev NO-UNDO.
    DEFINE INPUT PARAMETER p-nr-pedido like ped-venda.nr-pedido NO-UNDO.

    /** Variaveis Locais **/
    DEFINE VARIABLE c-plan-modelo AS CHARACTER NO-UNDO.
    DEFINE VARIABLE c-plan-destino AS CHARACTER NO-UNDO.
    DEFINE VARIABLE i-dec AS DECIMAL EXTENT 12 NO-UNDO.
    DEFINE VARIABLE i-data AS DATE EXTENT 12 NO-UNDO.
    DEFINE VARIABLE h-Acomp AS HANDLE NO-UNDO.
    DEFINE VARIABLE v-num-reg-lidos AS INTEGER INITIAL 0 NO-UNDO.
    DEFINE VARIABLE i-int AS INTEGER EXTENT 12 INITIAL 0 NO-UNDO.
    DEFINE VARIABLE i-variaveis AS CHARACTER EXTENT 12 INITIAL "" NO-UNDO.
    DEFINE VARIABLE c-OC AS CHARACTER NO-UNDO.
    DEFINE VARIABLE BrOffice as com-handle.
    DEFINE VARIABLE Desktop as com-handle.
    DEFINE VARIABLE Planilha as com-handle.
    DEFINE VARIABLE Documento as com-handle.
    DEFINE VARIABLE Padrao as com-handle.
    DEFINE VARIABLE Cabecalho as com-handle.
    DEFINE VARIABLE Rodape as com-handle.
    DEFINE VARIABLE Borda as com-handle.
    DEFINE VARIABLE Celula as com-handle.
    DEFINE VARIABLE cc as RAW EXTENT 50 .
    DEFINE VARIABLE loop as int.
    DEFINE VARIABLE c-arquivo AS CHARAC.
    RUN utp/ut-acomp.p persistent set h-acomp. {utp/ut-liter.i Rotulo002 *}
    RUN pi-inicializar in h-acomp (input RETURN-VALUE ).
    RUN pi-acompanhar in h-acomp (input "Gerando Rótulos Mod 002, Aguarde...." ).

    /*Definindo o modelo e o destino*/
    ASSIGN c-plan-modelo = "//192.168.0.7/dts/totvs/datasul/prd/ERP/Desenvolvimento/modelos/Rotulo.ots" .
    /**Apaga Todos Arquivos Gerados temp */
    DOS SILENT DEL "C:\TEMP\*.OTS".
    IF SEARCH(c-plan-modelo) <> ? THEN DO:
    IF SEARCH(c-plan-destino) <> ? THEN DOS SILENT DEL VALUE(c-plan-destino).

    RUN pi-acompanhar in h-acomp (input "Gerando Excel, Aguarde..." ).
    FOR EACH PRE-APONTAMENTO NO-LOCK
    where PRE-APONTAMENTO.cod-estabel = p-Cod-Estabel
    and PRE-APONTAMENTO.nome-abrev = p-nome-abrev
    and PRE-APONTAMENTO.nr-pedido = p-nr-pedido,
    each ped-venda no-lock
    where ped-venda.nr-pedcli = PRE-APONTAMENTO.nr-pedcli and
    ped-venda.nr-pedido = PRE-APONTAMENTO.nr-pedido and
    ped-venda.nome-abrev = PRE-APONTAMENTO.nome-abrev,
    FIRST transporte no-lock
    where transporte.nome-abrev = ped-venda.nome-transp,
    each emitente no-lock
    where emitente.nome-abrev = ped-venda.nome-abrev,
    each item no-lock
    where item.it-codigo = PRE-APONTAMENTO.it-codigo
    break by PRE-APONTAMENTO.cod-estabel
    by PRE-APONTAMENTO.nr-ord-produ
    by PRE-APONTAMENTO.nr-pedcli
    by PRE-APONTAMENTO.identificacao:

    if first-of(PRE-APONTAMENTO.identificacao) then do:
    assign v-num-reg-lidos = v-num-reg-lidos + 1.

    create "com.sun.star.ServiceManager" BrOffice.
    Desktop = BrOffice:createinstance("com.sun.star.frame.Desktop").
    /* Abre um documento no disco Documento = Desktop:loadComponentFromURL("file:///" + c-plan-Modelo ,"_blank",0,cc[v-num-reg-lidos]) NO-ERROR.
    /** Definindo Arquivo Saida **/
    c-plan-destino = "c:/temp/" + ped-venda.nr-pedcli + "_" + STRING(v-num-reg-lidos) + ".ots".
    /* c-plan-ModeloAux = "c:/temp/Modelo" + STRING(v-num-reg-lidos) + ".ots".

    /*Copiando o modelo para o destino*/
    OS-COPY value(c-plan-modelo) VALUE(c-plan-ModeloAux).*/

    /* Remove Planilhas padrao */
    do while Documento:getSheets:getCount > 1:
    Planilha = Documento:getSheets:getByIndex(1).
    Documento:getSheets:removeByName(Planilha:name ).
    end.
    ASSIGN Planilha = Documento:getSheets:getByIndex(0).
    Planilha:name = "Rotulo_" + STRING(v-num-reg-lidos).

    FIND FIRST PED-ITEM OF PED-VENDA
    WHERE PED-ITEM.NR-SEQUEN = PRE-APONTAMENTO.seq-pv
    AND PED-ITEM.IT-CODIGO = PRE-APONTAMENTO.IT-CODIGO
    AND PED-ITEM.COD-REFER = PRE-APONTAMENTO.COD-REFER
    AND ped-item.vl-preuni > 0 NO-LOCK NO-ERROR.
    IF AVAIL PED-ITEM THEN DO:
    ASSIGN i-variaveis[1] = "" i-variaveis[2] = "".
    IF PED-ITEM.OBSERVACAO <> "" THEN assign c-OC = STRING(SUBSTRING(ped-item.observacao,1,32)).
    ELSE assign c-OC = "".
    FIND FIRST var-result USE-INDEX ID WHERE var-result.item-cotacao = ped-item.it-codigo
    AND var-result.nr-estr = ped-item.nr-config
    AND var-result.nome-var = "DIIN" NO-LOCK NO-ERROR.
    IF AVAIL var-result THEN ASSIGN i-variaveis[1] = STRING(var-result.valor-dec,">>>9").

    FIND FIRST var-result USE-INDEX ID WHERE var-result.item-cotacao = ped-item.it-codigo
    AND var-result.nr-estr = ped-item.nr-config
    AND var-result.nome-var = "DIEX" NO-LOCK NO-ERROR.
    IF AVAIL var-result THEN ASSIGN i-variaveis[2] = STRING(var-result.valor-dec,">>>9").

    END.

    assign i-int[1] = 0
    i-dec[2] = pre-apontamento.peso-pallet.
    i-dec[12] = 0.
    Planilha:GetCellByPosition(02,07):VALUE = ped-venda.cod-emitente.
    Planilha:GetCellByPosition(00,08):STRING = ( ped-venda.nome-abrev + "/" + emitente.nome-emit) .
    Planilha:GetCellByPosition(00,11):STRING = ( ped-venda.cidade + " / " + ped-venda.estado) .
    Planilha:GetCellByPosition(09,07):STRING = c-OC .
    Planilha:GetCellByPosition(07,09):VALUE = ped-venda.nr-pedido.

    IF transporte.nome-abrev = 'LIMER-CART' THEN Planilha:GetCellByPosition(00,13):STRING = "".
    ELSE DO:
    Planilha:GetCellByPosition(00,14):STRING = STRING(transporte.cod-transp,">>,>99") + ' - ' + transporte.nome-abrev + " / " + transporte.nome .
    Planilha:GetCellByPosition(00,15):STRING = transporte.endereco + " - " + transporte.bairro + " " + transporte.cidade + "/" + transporte.estado.
    END.
    Planilha:GetCellByPosition(00,17):STRING = PRE-APONTAMENTO.it-codigo .
    Planilha:GetCellByPosition(00,18):STRING = item.desc-item .
    Planilha:GetCellByPosition(05,17):VALUE = PRE-APONTAMENTO.nr-ord-produ .
    Planilha:GetCellByPosition(07,17):VALUE = PRE-APONTAMENTO.dt-pesagem .
    Planilha:GetCellByPosition(00,20):VALUE = PRE-APONTAMENTO.largura .
    Planilha:GetCellByPosition(03,20):VALUE = i-variaveis[2] .
    Planilha:GetCellByPosition(05,20):VALUE = i-variaveis[1] .
    Planilha:GetCellByPosition(07,20):VALUE = PRE-APONTAMENTO.dt-validade .
    Planilha:GetCellByPosition(03,23):STRING = CAPS(PRE-APONTAMENTO.identificacao) .
    Planilha:GetCellByPosition(04,24):VALUE = PRE-APONTAMENTO.peso-pallet .
    end.
    assign i-int[01] = i-int[01] + 1
    i-dec[02] = i-dec[02] + PRE-APONTAMENTO.peso-bru
    i-dec[12] = i-dec[12] + PRE-APONTAMENTO.peso-liq.

    if last-of(PRE-APONTAMENTO.identificacao) then do:
    Planilha:GetCellByPosition(00,23):VALUE = i-int[01]. /*Nr Bobinas **/
    Planilha:GetCellByPosition(05,23):VALUE = i-dec[12] /*Peso Liquido**/.
    Planilha:GetCellByPosition(07,23):VALUE = i-dec[02] /**Peso Bruto **/.
    /* SALVA O ARQUIVO COM O NOME E CAMINHO ESPECIFICADO */
    Documento:storeAsUrl("file:///" + c-plan-destino ,cc[v-num-reg-lidos] ).

    /* IF v-num-reg-lidos = 1 THEN system-dialog printer-setup.*/

    /* Imprimi documento */
    Documento:SetPropertyValue("Print", SESSION:pRINTER-NAME).
    Documento:SetPropertyValue("CopyCount", 2). /* Número de cópias - Comando não funciona */
    Documento:SetPropertyValue("Collate",FALSE).
    Documento:SetPropertyValue("Wait", TRUE). /*Caso der erro na impressão retorna*/
    Documento:pRINT(cc[v-num-reg-lidos]).

    /* Finaliza BrOffice */
    PAUSE(3) .
    Documento:dispose().
    Desktop:terminate().
    END.
    END.
    END.

    release object Documento.
    release object Planilha.
    release object Desktop.
    RELEASE OBJECT BrOffice.
    RUN pi-finalizar in h-acomp .

Compartilhe esta Página