FORMS X EXCEL

Visualizando 5 posts - 1 até 5 (de 5 do total)
  • Autor
    Posts
  • #74594
    Avatar de wfoguelwfoguel
    Participante

    ❓ ➡ Gostaria de saber se alguem j? gravou os dados que retornam de um PL/SQL em Excel ? Pois n?o consigo trazer e nem saber por onde come?ar.

    Obrigado

    #75048
    Anônimo
    Convidado

    Procure no help pela fun??o DDE. Ela ir? te ajudar a transferir os dados do oracle para o excel

    #75100
    Anônimo
    Convidado

    Primeiro voce grava os dados num arquivo txt, e depois por mala direta vc grava no excell.
    A chamada do excell pode ser feita dentro do proprio forms….
    olha um exemplo… ? meio grande…rs

    DECLARE
    AppID PLS_INTEGER;
    VAR_CAMINHO VARCHAR2(32767);
    in_file TEXT_IO.FILE_TYPE;
    endereco varchar2(85):= ”;
    endereco2 char(50) := ”;
    CURSOR C_REC_TRA IS

    SEU SELECT
    BEGIN

                msg_alert('depois','I',false); 
                in_file := TEXT_IO.FOPEN('C:isentos.txt','W');
                            TEXT_IO.PUT(in_file,''||('Imovel')||'|');
                    TEXT_IO.PUT(in_file,''||('Endereco')||'|');
                TEXT_IO.PUT(in_file,''||('Setor')||'|');
                            TEXT_IO.PUT(in_file,''||('Cidade')||'|');
                        TEXT_IO.PUT_line(in_file,''||('Condicao')||'');
                         FOR R_REG IN C_REC_TRA LOOP
                         BEGIN
                          endereco := rtrim(ltrim(dec_endereco(r_reg.imu_imovel_Cd,1)));
                TEXT_IO.PUT(in_file,''||(r_reg.imovel)||'|');
                    TEXT_IO.PUT(in_file,''||(endereco)||'|');  
                        TEXT_IO.PUT(in_file,''||(r_reg.setor)||'|');  
                        TEXT_IO.PUT(in_file,''||(r_reg.cidade)||'|');  
                    TEXT_IO.PUT_line(in_file,''||(r_reg.CON_CONDICAO_DS)||'');
                    NEXT_RECORD;
    
           END;
    

    END LOOP;
    SET_APPLICATION_PROPERTY(CURSOR_STYLE, ‘DEFAULT’);
    TEXT_IO.FCLOSE(in_file);
    –msg_alert(‘terminei’,’I’,false);
    AppID := DDE.APP_BEGIN(‘C:Excel.exe c:modelo_isentos.xls’,
    DDE.APP_MODE_MAXIMIZED);
    OU

    /VAR_CAMINHO := ‘Micros~2’;
    AppID := DDE.APP_BEGIN(‘C:Arquiv~1’||var_caminho||’Officewinword.exe s:GIUmodelo_isentos1.xls’,
    DDE.APP_MODE_MAXIMIZED);
    /
    END;

    #75107
    Avatar de Marcio68AlmeidaMarcio68Almeida
    Participante

    Sei que o Excel pode se conectar diretamente ao Oracle via ODBC, j? vi processos sendo executados retornando a partir de consultas, portanto imagino que tamb?m d? para retornar a partir de procedures ou functions…
    Agora… como fazer a conec??o e estrair a consulta tem que pesquisar, j? que o que eu vi j? estava prontos e rodando, n?o vi como faz…

    #84854
    Avatar de wfoguelwfoguel
    Participante

    Depois de um tempão tentando, consegui gerar um excel pelo FORMS, o comando é este, aí é só substituir pelo dados desejados.

    Declare
    — Declare handles to the OLE objects
    application ole2.obj_type;
    workbooks ole2.obj_type;
    workbook ole2.obj_type;
    worksheet ole2.obj_type;
    cell ole2.obj_type;
    — Declare handles to OLE argument lists
    args ole2.list_type;

     rowcount number := 0;
    

    /————————————————————————-
    Processo ………….: EXCEL_x_FORMS
    Nome Externo ……: GERA_EXCEL_x_FORMS.SQL
    Tipo ………………..: Procedure
    Objetivo …………..: Gerar uma planilha Excel, com os resultados de uma query.
    Data Ultima Alter..: 25/10/2005
    ————————————————————————-
    /

    Begin
    — Create handle to aplication object
    application := ole2.create_obj(‘Excel.Application’);

    — Create a Workbooks collection and add new Workbook to Workbooks collection
    workbooks := ole2.get_obj_property(application, ‘Workbooks’);
    workbook := ole2.get_obj_property(workbooks,’Add’);

    — Open worksheet Plan1 of that Workbook
    args := ole2.create_arglist;
    ole2.add_arg(args,’Plan1′);
    worksheet := ole2.get_obj_property(workbook, ‘Worksheets’,args);
    ole2.destroy_arglist(args);

    /*
    nesse caso esta lendo os dados de uma Query e populando uma planilha e exportando os dados retornados.
    Mas com uma observação: Os dados podem ser populado dinamicamentes, mas abaixo está um modelo que está
    sendo populado por uma query.
    */

    First_Record;
    ———————————————–CABECARIO————————————————-
    for i in (select ‘X’
    from dual)Loop


    –Irá retornar apenas 1 (uma) linha para o cabeçario, o que pode ser feito e eu ainda não fiz, foi montar ele todo dinamico.


    rowcount := 1;
    
    -- Coluna_1
       args := ole2.create_arglist;
       ole2.add_arg(args, rowcount); -- linha 
       ole2.add_arg(args, 1);        -- coluna
       cell := ole2.get_obj_property(worksheet, 'Cells', args);
       ole2.destroy_arglist(args);
       ole2.set_property(cell, 'Value', 'Coluna_1');
       ole2.release_obj(cell);
    
    -- Coluna_2
       args := ole2.create_arglist;
       ole2.add_arg(args, rowcount); -- row number
       ole2.add_arg(args, 2);        -- column number
       cell := ole2.get_obj_property(worksheet, 'Cells', args);
       ole2.destroy_arglist(args);
       ole2.set_property(cell, 'Value', 'Coluna_2');
       ole2.release_obj(cell);
    
    -- Coluna_3
       args := ole2.create_arglist;
       ole2.add_arg(args, rowcount); -- row number 
       ole2.add_arg(args,3);         -- column number
       cell := ole2.get_obj_property(worksheet, 'Cells', args);
       ole2.destroy_arglist(args);
       ole2.set_property(cell, 'Value', 'Coluna_3');
       ole2.release_obj(cell);
    
    -- Coluna_4
       args := ole2.create_arglist;
       ole2.add_arg(args, rowcount); -- row number
       ole2.add_arg(args, 4);        -- column number
       cell := ole2.get_obj_property(worksheet, 'Cells', args);
       ole2.destroy_arglist(args);
       ole2.set_property(cell, 'Value', 'Coluna_4');
       ole2.release_obj(cell);
    
    -- Coluna_5
       args := ole2.create_arglist;
       ole2.add_arg(args, rowcount); -- row number
       ole2.add_arg(args, 5);        -- column number
       cell := ole2.get_obj_property(worksheet, 'Cells', args);
       ole2.destroy_arglist(args);
       ole2.set_property(cell, 'Value', 'Coluna_5');
       ole2.release_obj(cell);
    
    -- Coluna_6
       args := ole2.create_arglist;
       ole2.add_arg(args, rowcount); -- row number
       ole2.add_arg(args, 6);        -- column number
       cell := ole2.get_obj_property(worksheet, 'Cells', args);
       ole2.destroy_arglist(args);
       ole2.set_property(cell, 'Value', 'Coluna_6');
       ole2.release_obj(cell);
    

    End Loop;


    ——————————————CORPO——————————————–


    for i in (select ‘teste 1′ Coluna_1,
    ’25/10/2005’ Coluna_2,
    ‘teste 3’ Coluna_3,
    ‘teste 4’ Coluna_4,
    ‘teste 5’ Coluna_5,
    ‘teste 6’ Coluna_6
    from dual )Loop

    rowcount := rowcount +1;
    
    -- Coluna_1
        args := ole2.create_arglist;
        ole2.add_arg(args, rowcount); -- linha 
        ole2.add_arg(args, 1);        -- coluna
        cell := ole2.get_obj_property(worksheet, 'Cells', args);
        ole2.destroy_arglist(args);
        If rowcount = 1 Then
       ole2.set_property(cell, 'Value', 'Coluna_1');
        Else
       ole2.set_property(cell, 'Value', i.Coluna_1);
        End If;
        ole2.release_obj(cell);
    
    -- Coluna_2
        args := ole2.create_arglist;
        ole2.add_arg(args, rowcount); -- row number
        ole2.add_arg(args, 2);        -- column number
        cell := ole2.get_obj_property(worksheet, 'Cells', args);
        ole2.destroy_arglist(args);
        If rowcount = 1 Then
           ole2.set_property(cell, 'Value', 'Coluna_2');
        Else
           ole2.set_property(cell, 'Value', TO_CHAR(i.Coluna_2,'DD/MM/RR'));
        End If;
        ole2.release_obj(cell);
    
    -- Coluna_3
    args := ole2.create_arglist;
    ole2.add_arg(args, rowcount); -- row number 
    ole2.add_arg(args,3);         -- column number
        cell := ole2.get_obj_property(worksheet, 'Cells', args);
        ole2.destroy_arglist(args);
        If rowcount = 1 Then
           ole2.set_property(cell, 'Value', 'Coluna_3');
        Else 
           ole2.set_property(cell, 'Value', i.Coluna_3);
        End If;
        ole2.release_obj(cell);
    
    -- Coluna_4
        args := ole2.create_arglist;
    ole2.add_arg(args, rowcount); -- row number
    ole2.add_arg(args, 4);        -- column number
    cell := ole2.get_obj_property(worksheet, 'Cells', args);
    ole2.destroy_arglist(args);
    If rowcount = 1 Then
       ole2.set_property(cell, 'Value', 'Coluna_4');
    Else
       ole2.set_property(cell, 'Value', i.Coluna_4);
    End If;
    ole2.release_obj(cell);
    
    -- Coluna_5
        args := ole2.create_arglist;
    ole2.add_arg(args, rowcount); -- row number
    ole2.add_arg(args, 5);        -- column number
    cell := ole2.get_obj_property(worksheet, 'Cells', args);
    ole2.destroy_arglist(args);
    If rowcount = 1 Then
       ole2.set_property(cell, 'Value', 'Coluna_5');
    Else
       ole2.set_property(cell, 'Value', i.Coluna_5);
    End If;
    ole2.release_obj(cell);
    
    -- Coluna_6
        args := ole2.create_arglist;
        ole2.add_arg(args, rowcount); -- row number
        ole2.add_arg(args, 6);        -- column number
        cell := ole2.get_obj_property(worksheet, 'Cells', args);
        ole2.destroy_arglist(args);
        If rowcount = 1 Then
           ole2.set_property(cell, 'Value', 'Coluna_6');
        Else
           ole2.set_property(cell, 'Value', i.Coluna_6);
        End If;
        ole2.release_obj(cell);
    

    End Loop;

    — Habilita o usuario a ver o resultado da aplicação no Excel.
    ole2.set_property(application,’Visible’, True);

    — Release all OLE object handles
    ole2.release_obj(worksheet);
    ole2.release_obj(workbook);
    ole2.release_obj(workbooks);
    ole2.release_obj(application);

    First_Record;
    End;

    Existe outras possíbilidades, como por exemplo colocar em negrito o cabeçario, mas aí tem que ir procurando.

    Espero ter ajudado alguem com esta dica.

Visualizando 5 posts - 1 até 5 (de 5 do total)
  • Você deve fazer login para responder a este tópico.
plugins premium WordPress