Desafio Word

Dicas do Oracle Forms Builder - Blocos, Itens, LOV, Canvas, Triggers, comandos, PLL, d2kwutil, FMB, Alert, menus, etc
Responder
lamanita
Rank: Programador Pleno
Rank: Programador Pleno
Mensagens: 42
Registrado em: Seg, 17 Mai 2004 2:41 pm
Localização: Porto Alegre - RS

Alguém sabe como gerar um documento word PROTEGIDO de dentro do Forms usando o text_io ?
Valeu pessoal...
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Cara...
Eu existe um pacote do Forms chamado WORDOLE. Com ele, você consegue fazer algumas coisas no WORD de dentro do Forms.

Search_and_replace, SetCellText, etc...

Será que você não consegue fazer isso usando Macros do WORD?
Tipo, cria um arquivo TXT com o TextIO. Abre ele no WORD via wordole, daí dá um jeito de rodar uma macro que protege o documento... (Não sei se isso é possível)

Mas acho mais fácil você achar algum arquivo que gere PDF. Na internet se acha programinhas que geram PDF. O Reports também gera PDFs...

Abaixo, o código do pacote WORDOLE...

Selecionar tudo

PACKAGE WordOLE IS

  function  StartWord(MakeVisible in BOOLEAN) return BOOLEAN;
  function  OpenDoc  (DocumentName in VARCHAR2) return OLE2.OBJ_TYPE;
  function  SaveAs   (DocumentName in VARCHAR2, 
                      hDocs in OLE2.OBJ_TYPE) return OLE2.OBJ_TYPE;

  procedure CloseDoc (DocumentHandle in OLE2.OBJ_TYPE);  
  
  procedure PrintDoc (DocumentHandle in OLE2.OBJ_TYPE);  
  
  procedure ShutDown;  

  -- Get and Set Type Functions
  procedure Search_and_replace (TargetText      in VARCHAR2, 
                                ReplaceWithText in VARCHAR2);
                                                                
  -- Navigation Functions - Return the Range object for the thing you goto
  function GotoBookMark (DocumentHandle in OLE2.OBJ_TYPE, 
                         Bookmark in VARCHAR2) return OLE2.OBJ_TYPE;
                         
  function GotoTable    (DocumentHandle in OLE2.OBJ_TYPE, 
                         ThisTable in PLS_INTEGER DEFAULT 1) return OLE2.OBJ_TYPE;

  -- Table Cell Related Functions   -- Goto Cell returns the Cell handle
  function GotoCell     (DocumentHandle in OLE2.OBJ_TYPE, 
                         ThisTable      in PLS_INTEGER,
                         CellColumn     in PLS_INTEGER,
                         CellRow        in PLS_INTEGER) return OLE2.OBJ_TYPE;
                         
  procedure SetCellText (DocumentHandle in OLE2.OBJ_TYPE, 
                         ThisTable      in PLS_INTEGER,
                         CellColumn     in PLS_INTEGER,
                         CellRow        in PLS_INTEGER,
                         Text           in VARCHAR2);    

  -- Header and footer functions  
  procedure SetHeaderText (DocumentHandle in OLE2.OBJ_TYPE, 
                           SectionNo in PLS_INTEGER, 
                           Text in VARCHAR2);
                           
  procedure SetFooterText (DocumentHandle in OLE2.OBJ_TYPE, 
                           SectionNo in PLS_INTEGER, 
                           Text in VARCHAR2);
                                                 
  -- Bookmark related Functions
  function DoesBookmarkExist(DocumentHandle in OLE2.OBJ_TYPE, 
                             Bookmark in VARCHAR2) return BOOLEAN;
                             
  procedure SetBookmarkText (DocumentHandle in OLE2.OBJ_TYPE, 
                             Bookmark in VARCHAR2, Text in VARCHAR2);
  
END;

Selecionar tudo

PACKAGE BODY WordOLE IS

  -- Private Variables  
  hApp OLE2.OBJ_TYPE; 

  /* Application handle for Word */  
  -- Private Procedures

  procedure SetHeaderFooterText(DocumentHandle in OLE2.OBJ_TYPE, 
                                SectionNo in PLS_INTEGER,
                                Text in VARCHAR2, Type in PLS_INTEGER);


  function StartWord (MakeVisible in BOOLEAN) return BOOLEAN is
   bRC BOOLEAN := FALSE;  
   
   begin     
   
    hApp := ole2.create_obj('Word.Application');
    if hApp = 0 
    then bRC := FALSE;    
    else bRC := TRUE;
         if MakeVisible 
         then ole2.set_property(hApp,'Visible',1);
         end if;    
    end if;    
    
    return bRC;  
    
   end;  
   
  function OpenDoc (DocumentName in VARCHAR2) return OLE2.OBJ_TYPE is
   hDocs OLE2.OBJ_TYPE;   
   hDoc  OLE2.OBJ_TYPE;      
   hArgs OLE2.LIST_TYPE;  
   
   begin
   
    -- Get the documents Collection
   hDocs := OLE2.GET_OBJ_PROPERTY(hApp,'Documents');  
     
   -- Open the specified Doc   
   hArgs   := OLE2.CREATE_ARGLIST; 
   OLE2.ADD_ARG(hArgs, DocumentName); 
   
   hDoc    := OLE2.INVOKE_OBJ(hDocs, 'Add', hArgs); 
   OLE2.DESTROY_ARGLIST(hArgs);    
   
   -- Release the documents collection but not the Doc
   OLE2.RELEASE_OBJ(hDocs);   
   return hDoc;  
  
  end;  

  function SaveAs (DocumentName in VARCHAR2, 
                   hDocs in OLE2.OBJ_TYPE) return OLE2.OBJ_TYPE is
   --hDocs OLE2.OBJ_TYPE;   
   hDoc  OLE2.OBJ_TYPE;      
   hArgs OLE2.LIST_TYPE;  
   
   begin
   
    -- Get the documents Collection
   --hDocs := OLE2.GET_OBJ_PROPERTY(hApp,'Documents');  
     
   -- Open the specified Doc   
   hArgs   := OLE2.CREATE_ARGLIST; 
   OLE2.ADD_ARG(hArgs, DocumentName); 
   hDoc    := OLE2.INVOKE_OBJ(hDocs, 'SaveAs', hArgs); 
   OLE2.DESTROY_ARGLIST(hArgs);    
   
   -- Release the documents collection but not the Doc
   OLE2.RELEASE_OBJ(hDocs);   
   return hDoc;  
  
  end;  
  
  procedure CloseDoc(DocumentHandle in OLE2.OBJ_TYPE) is  
  begin
    OLE2.INVOKE(DocumentHandle,'Close');  
  end;    
  
  procedure ShutDown is
    hDocs       OLE2.OBJ_TYPE;  
    
  begin     

    -- Get the documents Collection
    hDocs := OLE2.GET_OBJ_PROPERTY(hApp,'Documents');
    
    -- Just Close any open docs    
    OLE2.INVOKE(hDocs,'Close');
    OLE2.RELEASE_OBJ(hDocs);         
    
    -- The Quit and clean up.
    OLE2.INVOKE(hApp,'Quit');    
    OLE2.RELEASE_OBJ(hApp);  

  end;  

-- *************************************************
  procedure PrintDoc(DocumentHandle in OLE2.OBJ_TYPE) is  
  begin
    OLE2.INVOKE(DocumentHandle,'PrintOut');  
--    OLE2.INVOKE(DocumentHandle,'wdDialogFilePrint');  
--Dialogs(wdDialogFilePrint).Show
    
  end;    
  
--*******************************  
  
    
  PROCEDURE Search_and_replace (TargetText in VARCHAR2, 
                                ReplaceWithText in VARCHAR2) IS 
    hSelection  OLE2.OBJ_TYPE;     
    hFind       OLE2.OBJ_TYPE; 
    hArgs       OLE2.LIST_TYPE;  
    
  BEGIN
  
     hSelection := OLE2.GET_OBJ_PROPERTY(hApp,'Selection');
    
     -- Now get the "Find" object from the selection
     hFind      := OLE2.GET_OBJ_PROPERTY(hSelection,'Find');
    
     -- Now we can call the execute method to do the search/replace
     hArgs := OLE2.CREATE_ARGLIST;
     OLE2.ADD_ARG(hArgs,TargetText);        /* FindText */
     OLE2.ADD_ARG(hArgs,0);                 /* MatchCase */
     OLE2.ADD_ARG(hArgs,0);                 /* MatchWholeWord */
     OLE2.ADD_ARG(hArgs,0);                 /* MatchWildCards */
     OLE2.ADD_ARG(hArgs,0);                 /* MatchSoundsLike */
     OLE2.ADD_ARG(hArgs,0);                 /* MatchAllWordForms */
     OLE2.ADD_ARG(hArgs,1);                 /* Forward */
     OLE2.ADD_ARG(hArgs,1);                 /* Wrap wdFindAsk=2,wbFindContinue=1, wdFindStop=0 */
     OLE2.ADD_ARG(hArgs,0);                 /* Format */
     OLE2.ADD_ARG(hArgs,ReplaceWithText);   /* ReplaceWith */
     OLE2.ADD_ARG(hArgs,2);                 /* Replace wdReplaceAll=2,wdReplaceOne=1, wbReplaceNone=0 */
     OLE2.INVOKE(hFind,'Execute',hArgs);      
     OLE2.DESTROY_ARGLIST(hArgs);
 
     -- Clean Up     
     --OLE2.RELEASE_OBJ(hFind); 
     --OLE2.RELEASE_OBJ(hSelection);      
     --OLE2.RELEASE_OBJ(hApp);  

  END;   
  
  
  function GotoBookMark (DocumentHandle in OLE2.OBJ_TYPE, 
                         Bookmark in VARCHAR2) return OLE2.OBJ_TYPE is
    hArgs      OLE2.LIST_TYPE;    
    hRange     OLE2.OBJ_TYPE;  
    
  begin 
  
        hArgs  := OLE2.CREATE_ARGLIST; 
        OLE2.ADD_ARG(hArgs,-1);                 /* What? = wdGoToBookmark */
        OLE2.ADD_ARG(hArgs, 0);         /* Which? */
        OLE2.ADD_ARG(hArgs, 0);        /* Count */
        OLE2.ADD_ARG(hArgs, Bookmark);  /* Name */
        hRange := OLE2.INVOKE_OBJ(DocumentHandle,'Goto',hArgs);
        OLE2.DESTROY_ARGLIST(hArgs);     
        OLE2.INVOKE(hRange,'Select');

        return hRange;  
    
  end;  
  
  
  function GotoTable    (DocumentHandle in OLE2.OBJ_TYPE, 
                         ThisTable in PLS_INTEGER DEFAULT 1) 
                       return OLE2.OBJ_TYPE is
    hArgs      OLE2.LIST_TYPE;    
    hRange     OLE2.OBJ_TYPE;  
    
  begin 
  
    hArgs       := OLE2.CREATE_ARGLIST; 
    OLE2.ADD_ARG(hArgs,2);                  /* What? = wdGoToTable */
    OLE2.ADD_ARG(hArgs, 1);            /* Which? = wdGoToAbsolute*/
    OLE2.ADD_ARG(hArgs, ThisTable);     /* Count */
    hRange := OLE2.INVOKE_OBJ(DocumentHandle,'Goto',hArgs);
    OLE2.DESTROY_ARGLIST(hArgs);    
    OLE2.INVOKE(hRange,'Select'); 
    return hRange;  
    
  end;  
  
  
  
  function GotoCell     (DocumentHandle in OLE2.OBJ_TYPE, 
                         ThisTable      in PLS_INTEGER,
                         CellColumn     in PLS_INTEGER,
                         CellRow        in PLS_INTEGER) return OLE2.OBJ_TYPE
is 
                         
    hArgs      OLE2.LIST_TYPE;        
    hTables    OLE2.OBJ_TYPE; 
    hTable     OLE2.OBJ_TYPE;                         
    hColumns   OLE2.OBJ_TYPE; 
    hColumn    OLE2.OBJ_TYPE;                         
    hCells     OLE2.OBJ_TYPE;                         
    hCell      OLE2.OBJ_TYPE;                           
    
  begin 
  
  break;

        -- Get the Table Handle
        hTables := OLE2.GET_OBJ_PROPERTY(DocumentHandle,'Tables');
        hArgs       := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(hArgs,ThisTable);
        hTable := OLE2.INVOKE_OBJ(hTables,'Item',hArgs);
        OLE2.DESTROY_ARGLIST(hArgs);

        -- Get the Column Requested
        hColumns := OLE2.GET_OBJ_PROPERTY(hTable,'Columns');     
        hArgs       := OLE2.CREATE_ARGLIST; 
        OLE2.ADD_ARG(hArgs,CellColumn);
        hColumn := OLE2.INVOKE_OBJ(hColumns,'Item',hArgs); 
        OLE2.DESTROY_ARGLIST(hArgs);

        -- Get the Request Row
        hCells := OLE2.GET_OBJ_PROPERTY(hColumn,'Cells');
        hArgs       := OLE2.CREATE_ARGLIST;
        OLE2.ADD_ARG(hArgs,CellRow);
        hCell := OLE2.INVOKE_OBJ(hCells,'Item',hArgs);
        
        OLE2.DESTROY_ARGLIST(hArgs);
        OLE2.RELEASE_OBJ(hCells);
        OLE2.RELEASE_OBJ(hColumn);
        OLE2.RELEASE_OBJ(hColumns);
        OLE2.RELEASE_OBJ(hTable);
        OLE2.RELEASE_OBJ(hTable);
        OLE2.INVOKE(hCell,'Select');
        return hCell;  
  end;  
  
  
  procedure SetCellText (DocumentHandle in OLE2.OBJ_TYPE, 
                         ThisTable      in PLS_INTEGER,
                         CellColumn     in PLS_INTEGER,
                         CellRow        in PLS_INTEGER,
                         Text           in VARCHAR2) is                    
                         
    hCell  OLE2.OBJ_TYPE;    
    hRange OLE2.OBJ_TYPE;  
    
    begin 
        hCell := GotoCell(DocumentHandle,ThisTable,CellColumn,CellRow);
        hRange := OLE2.GET_OBJ_PROPERTY(hCell,'Range');
        OLE2.SET_PROPERTY(hRange,'Text',Text);
        OLE2.RELEASE_OBJ(hRange);
        OLE2.RELEASE_OBJ(hCell);
    end;    
    
    
  procedure SetHeaderText (DocumentHandle in OLE2.OBJ_TYPE, 
                           SectionNo in PLS_INTEGER, 
                           Text in VARCHAR2) is
  begin         
    SetHeaderFooterText(DocumentHandle, SectionNo, Text,1);
  end;  
  
  
  procedure SetFooterText (DocumentHandle in OLE2.OBJ_TYPE, 
                           SectionNo in PLS_INTEGER, 
                           Text in VARCHAR2) is
  begin         
    SetHeaderFooterText(DocumentHandle, SectionNo, Text,2);
  end;  
  
  procedure SetHeaderFooterText(DocumentHandle in OLE2.OBJ_TYPE, 
                                SectionNo in PLS_INTEGER,
                                Text in VARCHAR2, 
                                Type in PLS_INTEGER) is

    hSection  OLE2.OBJ_TYPE;
    hSections OLE2.OBJ_TYPE;
    hHFs      OLE2.OBJ_TYPE;
    hHF       OLE2.OBJ_TYPE;
    hRange    OLE2.OBJ_TYPE;
    hArgs     OLE2.LIST_TYPE;
    vcType    VARCHAR2(10);
    
    begin
    
    -- Get the handle to the requested Section
    hSections := OLE2.GET_OBJ_PROPERTY(DocumentHandle,'Sections');
    hArgs       := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(hArgs,SectionNo);
    hSection := OLE2.INVOKE_OBJ(hSections,'Item',hArgs);
    OLE2.DESTROY_ARGLIST(hArgs);

    if Type = 1 
    then /* Header */
         vcType := 'Headers';    
    else vcType := 'Footers';    
    end if;    
    
    -- Get the Primary Header or footer object
    hHFs := OLE2.GET_OBJ_PROPERTY(hSection,vcType);
    hArgs := OLE2.CREATE_ARGLIST;         
    OLE2.ADD_ARG(hArgs,1);
    hHF := OLE2.INVOKE_OBJ(hHFs,'Item',hArgs); 
            
    OLE2.DESTROY_ARGLIST(hArgs);        
    -- Get the Range for that 
    hRange := OLE2.GET_OBJ_PROPERTY(hHF,'Range');    
    -- Set the Text for that     
    OLE2.SET_PROPERTY(hRange,'Text',Text);    
    OLE2.RELEASE_OBJ(hRange);    
    OLE2.RELEASE_OBJ(hHF);
    OLE2.RELEASE_OBJ(hHFs);    
    OLE2.RELEASE_OBJ(hSection);
    OLE2.RELEASE_OBJ(hSections); 
    end;                 
    
    
  function DoesBookmarkExist (DocumentHandle in OLE2.OBJ_TYPE, 
                              Bookmark in VARCHAR2) 
           return BOOLEAN is
    iExists    PLS_INTEGER;    
    hArgs      OLE2.LIST_TYPE;
    hBookmarks OLE2.OBJ_TYPE;    
    mid pls_integer;  
    
  begin 
    
      hBookmarks := OLE2.GET_OBJ_PROPERTY(DocumentHandle,'Bookmarks');   
 

    -- Call the Exists Method for the Bookmarks Object
    hArgs       := OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(hArgs, Bookmark);
    iExists     := OLE2.INVOKE_NUM(hBookmarks, 'exists', hArgs);
    OLE2.DESTROY_ARGLIST(hArgs);

    OLE2.RELEASE_OBJ(hBookmarks);  

    if iExists = -1 
    then return TRUE;                                    
    else return FALSE;    
    end if;  
    
    RETURN NULL; 
    
  end;  
    
    
  procedure SetBookmarkText (DocumentHandle in OLE2.OBJ_TYPE, 
                             Bookmark in VARCHAR2, 
                             Text in VARCHAR2) is
    hRange OLE2.OBJ_TYPE;  
    begin 
        hRange := GoToBookmark(DocumentHandle, BookMark);
        OLE2.SET_PROPERTY(hRange,'Text',Text);        
        OLE2.RELEASE_OBJ(hRange);
    end;  
      
END;
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Esqueci de mostrar como se faz pra substituir...

Selecionar tudo

  -- Substitui no WORD
voleobj:=wordole.opendoc(vdiretorio_temp||'\texto_proposta.doc');
       wordole.Search_and_replace ('&DOC_DIA',to_char(:CONTROLE.pro_dat,'DD'));	
       wordole.Search_and_replace ('&DOC_mês',rtrim(to_char(:CONTROLE.pro_dat,'MONTH')));	
       wordole.Search_and_replace ('&DOC_ANO',to_char(:CONTROLE.pro_dat,'RRRR'));	

       wordole.Search_and_replace ('&DOC_COD',:CONTROLE.pro_cod);	
       wordole.Search_and_replace ('&DOC_RSOC',:CONTROLE.pes_rsoc);	
       wordole.Search_and_replace ('&EMP_DSC',vemp_dsc);	
       wordole.Printdoc(voleobj);

       voleobj:=wordole.saveas(vdiretorio_temp||'\texto_proposta.doc',voleobj);
	
	
	     wordole.shutdown;
--      	wordole.CloseDoc(voleobj);
Se eu não me engano, deve estar carregada a PLL D2KWUTIL.PLL
lamanita
Rank: Programador Pleno
Rank: Programador Pleno
Mensagens: 42
Registrado em: Seg, 17 Mai 2004 2:41 pm
Localização: Porto Alegre - RS

O ideal seria gerar arquivos pdf de dentro do forms = )
Avatar do usuário
dr_gori
Moderador
Moderador
Mensagens: 5024
Registrado em: Seg, 03 Mai 2004 3:08 pm
Localização: Portland, OR USA
Contato:
Thomas F. G

Você já respondeu a dúvida de alguém hoje?
https://glufke.net/oracle/search.php?search_id=unanswered

Eu sempre uso o Reports pra gerar PDFs... Mas se você não tem, talvez pode usar o WORD pra criar o arquivo (usando o wordole acima) e mandando gerar o pdf com alguma tool como essa:

http://sourceforge.net/projects/pdfcreator

[]'s
Responder
  • Informação
  • Quem está online

    Usuários navegando neste fórum: Nenhum usuário registrado e 12 visitantes