Duvida Word

Discussão em 'Progress 4GL' iniciado por jaozi_nho, Abril 24, 2013.

  1. jaozi_nho

    jaozi_nho Membro Participativo

    Ola senhores, preciso fazer um relatório gerar um arquivo para Word, formato pode ser .rtf ou .doc , alguém tem algum material que possa me ajudar, preciso saber por exemplo...

    1 - como criar um novo arquivo .doc ou .rtf
    2 - como setar a fonte, pular linha, deixar texto em negrito
    3 - Criar tabelas, linhas X colunas
    4 - Pular Pagina

    Sobre criar um layout e substituir acho que não dará certo, pois o texto é muito dinâmico.

    Agradeço.
  2. lwazevedo

    lwazevedo Membro Ativo

    jaozi segue um material que utilizo para criar textos simples no word, mas acredito que já vai te dar um auxilio.

    Código:
    do with frame {&frame-name}:
    
    def var ch-Documento  as component-handle no-undo.
    def var ch-FormField  as component-handle no-undo.
    def var ch-Range      as component-handle no-undo.
    def var ch-Word       as component-handle no-undo.
    
    Create "Word.Application" ch-Word.
          ch-Documento = ch-word:documents:add().
          ch-word:visible = false.
          ch-Word:ScreenUpdating = yes.
          ch-Word:WindowState = 1.
          ch-Word:Visible = no.
          ch-Word:System:Cursor = 0.
          ch-word:Selection:Font:Bold = true.
          ch-word:selection:font:size = 20.
          ch-word:Selection:TypeText("                       Lista de Empregados").
    
    find first <tabela1> where <tabela1>.<campo>= <valor> no-lock no-error.
          if avail <tabela1> then do:
              for each <tabela2> where <tabela2>.<campo> = <tabela1>.<campo>no-lock.
                  for each <tabela3> where <tabela3>.<campo> = <tabela2>.<campo>  no-lock.
    
    ch-word:Selection:TypeText(chr(10)).                     
               ch-word:Selection:Font:Bold = true.                      
               ch-word:selection:font:size = 12.                                   
               ch-word:Selection:TypeText("Código: " ).        
               ch-word:Selection:Font:Bold = false.                     
               ch-word:Selection:TypeText(string(<tabela1>.<campo>)). 
               ch-word:Selection:TypeText(chr(10)).                     
               ch-word:Selection:Font:Bold = true.
               ch-word:Selection:TypeText("Nome Empregado " ).        
               ch-word:Selection:Font:Bold = false.                     
               ch-word:Selection:TypeText(string(<tabela1>.<campo>)).       
               ch-word:Selection:TypeText(chr(10)).                             
               ch-word:Selection:Font:Bold = true. 
               ch-word:Selection:TypeText("Função" ).        
               ch-word:Selection:Font:Bold = false. 
               ch-word:Selection:TypeText(string(<tabela2>.<campo>)).       
               ch-word:Selection:TypeText(chr(10)).                             
               ch-word:Selection:Font:Bold = true.
               ch-Word:System:Cursor = 1.
                  end.  
              end.
          end.
    
                 ch-word:visible = true.
               /*ch-Word:ScreenUpdating = no. */
               release object ch-Documento. 
               release object ch-word.
    end.
    END PROCEDURE.
    
  3. jaozi_nho

    jaozi_nho Membro Participativo

    Obrigado lwazevedo .

    Ajudou muito,
  4. lwazevedo

    lwazevedo Membro Ativo

    De nada, precisando é só postar ai....

    abraço.
  5. andivieira

    andivieira Sem Pontuação

    Boa tarde...

    lwazevedo, preciso preencher um doc word existente... como procedo para aplicar as alterações e salvá-lo com outro nome?

    Desde já agradeço.

    Atenciosamente,
  6. lwazevedo

    lwazevedo Membro Ativo

    andi acho que este código pode te ajudar...

    Código:
        find <tabela> where
            <tabela>.<campo> = <variavel><campo> no-lock no-error.
     
        assign c-nome-arq = <caminho onde esta o arqvuivo>
     
        create "Word.Application" ch-Word. 
     
        ch-Word:visible = false.
     
        ch-Doc = ch-Word:Documents:Add(c-nome-arq).
     
        ch-Doc:FormFields:Item("nomeCampo"):Result    = <tabela><campo>.
        ch-Doc:FormFields:Item("nomeCampo"):Result    = <tabela><campo>.
        ch-Doc:FormFields:Item("nomeCampo"):Result    = <tabela><campo>.
        ch-Doc:FormFields:Item("nomeCampo"):Result    = <tabela><campo>.
        ch-Doc:FormFields:Item("nomeCampo"):Result    = <tabela><campo>.
        ch-Doc:FormFields:Item("nomeCampo"):Result    = <tabela><campo>.
     
     
       /*se tiver tabela no documento*/
        ch-Word:selection:goto(-1,0,0,"Tabela1").
        ch-Range = ch-Doc:FormFields:Item("Tabela1"):Range:Next.
     
        ch-Doc:Tables:Add(ch-Range,1,1,1,0).
        ch-Word:selection:MoveRight().
     
     
        /*ch-Word:selection:font:name = "Times".*/
        ch-Word:selection:font:bold = yes .
        ch-Word:selection:font:size = 10.
     
     
        /*ch-Word:Selection:Shading:BackgroundPatternColor = 16777164.*/
        /*ch-Word:selection:TypeText("TITULOS").
        ch-Word:Selection:ParagraphFormat:Alignment = 1.
     
        ch-Word:selection:InsertRowsBelow ().*/
        ch-Word:Selection:Cells:Split(1,7,FALSE).
     
        ch-Word:selection:MoveLeft().
     
        ch-Word:selection:TypeText("nomecampo").
        ch-Word:Selection:Tables:Item(1):columns:item(1):width = 40.
        ch-Word:selection:MoveRight().
     
        ch-Word:selection:TypeText("nomecampo").
        ch-Word:Selection:Tables:Item(1):columns:item(2):width = 210.
        ch-Word:selection:MoveRight().
     
        ch-Word:selection:TypeText("nomecampo").
        ch-Word:Selection:Tables:Item(1):columns:item(3):width = 20.
        ch-Word:selection:MoveRight().
     
        ch-Word:selection:TypeText("nomecampo").
        ch-Word:Selection:Tables:Item(1):columns:item(4):width = 35.
        ch-Word:selection:MoveRight().
     
        ch-Word:selection:TypeText("nomecampo").
        ch-Word:Selection:Tables:Item(1):columns:item(5):width = 70.
        /*ch-Word:Selection:Tables(1):Columns(1):PreferredWidth = CentimetersToPoints(4.0).*/
        ch-Word:selection:MoveRight().    
     
        ch-Word:selection:TypeText("nomecampo").
        ch-Word:Selection:Tables:Item(1):columns:item(6):width = 40.
        ch-Word:selection:MoveRight().
     
        ch-Word:selection:TypeText("nomecampo").
        ch-Word:Selection:Tables:Item(1):columns:item(7):width = 40.
        ch-Word:selection:MoveRight().
     
     
        for each <tabela>:
     
            ch-Word:selection:InsertRowsBelow ().
            ch-Word:Selection:Shading:BackgroundPatternColor = -16777216.
            ch-Word:selection:font:bold = no.
            ch-Word:selection:MoveLeft().
            /*tt-sb-pavimentos.descricao   skip*/
            ch-Word:selection:TypeText(<tabela><campo>).
            ch-Word:selection:MoveRight().
     
            ch-Word:selection:TypeText(<tabela><campo>).
            ch-Word:selection:MoveRight().
     
            ch-Word:selection:TypeText(tt-reservas.un).
            ch-Word:selection:MoveRight().
     
            ch-Word:selection:TypeText(string(<tabela><campo>)).
            ch-Word:selection:MoveRight().
     
            if tt-reservas.lote <> "" then do:
                ch-Word:selection:TypeText(<tabela><campo>) .
                ch-Word:selection:MoveRight().
     
                ch-Word:selection:TypeText(<tabela><campo>).
                ch-Word:selection:MoveRight().
            end.
        end.
     
        ch-Word:selection:Tables:item(1):AutoFormat(1, True, True, True, false, True, False, True, False, false).
     
        c-saida = <diretorio de saíd - onde deseja salvar> ".doc".
        ch-Word:ActiveDocument:SaveAs ( c-saida, 0).
     
        Release Object ch-Word. 
        Release object ch-Doc.
     
        disp
            "Arquivo Word gerado: " no-label c-saida no-label format "x(60)" 
            with side-label frame f-arquivo width 132.
     
    end.
    
    
    JJSFFRANCO curtiu isso.

Compartilhe esta Página