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

Excel formatado no Progress Caracter

Discussão em 'Outros/Diversos' iniciado por jalegria, Abril 1, 2010.

  1. jalegria

    jalegria Membro Participativo

    Saudações Adoradores do Progress

    Estou colocando aqui uma humilde include para auxiliar na geração de relatorios no formato Excel para quem, como eu, tb utiliza o moderno Progress Caracter e só podia gerar no fantastico CSV.

    Ela gera arquivos em XML no padrão que o Excel 2003 ou superior (acho que no 2002 tb) entende.
    Coloquei as funções básicas para minha utilização e quem sabe seja util para alguem.

    Ela consegue gerar planilhas com formatação (cor de fundo, cor da fonte, tipo de fonte, tamanho de fonte, bordas), com a possibilidade de usar formulas (ao inves de ficar calculando no Progress), formatação de impressão, multiplas abas por arquivo, congelar 'n' linhas para cabeçalho de impressão, cabeçalho/rodapé (com numeração de pagina, etc...), impressão retrato ou paisagem com possibilidade de definir o zoom para caber na folha, mescla de celulas (por enqto somente na horizontal), criação de estilos, alinhamento horizontal e vertical.

    Se houver interesse do pessoal eu coloco alguns exemplos de utilização.
    E tb aceito sugestões...
    valeo...

    Código:
    /*==============================================================================
     Programa...: excel.i
     Descricao..: Include para geracao de planilhas Excel/XML
     Autor......: Jefferson Ferreira Alegria
     Data.......: 29/07/2008
    
     Obs........: Planilhas para o Excel 2003 ou superior
                  30/03/2010 - Atualizado - Melhoria na defini‡ao do nome do arq
    
    ==============================================================================*/
    
    def stream str-excel.
    def var xls-cell-count as int.
    def var xls-cols-count as int.
    def var xls-merge as int.
    def var xls-ctrl-styles as int.
    def var xls-header as char extent 3.
    def var xls-footer as char extent 3.
    def var xls-sheet-grid as log.
    
    def temp-table t-xls-styles no-undo
        field id as char
        field padrao as log
        index pk is primary unique id.
    
    def temp-table t-xls-attr no-undo
        field id      as char
        field tipo    as char
        field subtipo as char
        field attrs   as char extent 6.
    
    def buffer b-xls-attr for t-xls-attr.
    
    def temp-table t-xls-colors no-undo
        field cor as char.
    
    /* -------------------------------------------------------------------------- */
    
    FUNCTION Get-Param-Entry RETURN CHAR
      (p-list as char, p-name as char, p-separator as char):
      
      def var i  as int.
      def var rv as char.
      def var c  as char.
      
      if not trim(p-separator) > ' ' then p-separator = ';'.
      p-separator = substr(p-separator,1,1).
      
      do while rv = '' i = 1 to num-entries(p-list, p-separator):
    
        c = entry(i,p-list,p-separator).
    
        if num-entries(c,'=') = 2 and entry(1,c,'=') = p-name
        then rv = entry(2,c,'=').
        
      end.
      
      return rv.
      
    END FUNCTION.
    
    /* -------------------------------------------------------------------------- */
    
    FUNCTION Excel-Begin RETURN LOG (p-file as char, p-option as char):
    
      def var c as char.
    
    
      run Style-Default.
      empty temp-table t-xls-colors.
      
      if num-entries(p-file,'/') = 1
      then do:
        if entry(num-entries(p-file,'.'), p-file, '.') <> 'xml'
        then p-file = p-file + '.xml'.
    
        p-file = './' + p-file.
      end.
    
    
      xls-ctrl-styles = 0.
      output stream str-excel to value(p-file).
    
      put stream str-excel unformatted
        "<?xml version='1.0'?>" skip
        "<?mso-application progid='Excel.Sheet'?>" skip(1)
        "<Workbook " skip
        " xmlns='urn:schemas-microsoft-com:office:spreadsheet' " skip
        " xmlns:o='urn:schemas-microsoft-com:office:office' " skip
        " xmlns:x='urn:schemas-microsoft-com:office:excel' " skip
        " xmlns:ss='urn:schemas-microsoft-com:office:spreadsheet' " skip
        " xmlns:html='http://www.w3.org/TR/REC-html40'>" skip(1).
    
      put stream str-excel unformatted    
        " <DocumentProperties xmlns='urn:schemas-microsoft-com:office:office'>" skip
        "  <LastAuthor>ACME Inc.</LastAuthor>" skip
        "  <Created>" string(year(today),'9999') + '-' +
                      string(month(today),'99')  + '-' +
                      string(day(today),'99')    + 'T' +
                      string(time,'HH:MM:SS')    + 'Z</Created>' skip
        "  <Version>11.9999</Version>" skip
        " </DocumentProperties>" skip(1).
    
      return true.
      
    END FUNCTION.
    
    
    FUNCTION Excel-Style RETURN LOGICAL ():
    
      if xls-ctrl-styles = 0 then run Excel-Styles.
      return true.
    
    END FUNCTION.
    
    /* -------------------------------------------------------------------------- */
    
    PROCEDURE Excel-Styles:
    
      if xls-ctrl-styles = 0
      then do:
        run Excel-User-Colors.
      
        xls-ctrl-styles = 1.
        put stream str-excel unformatted " <Styles>" skip.
    
        run Excel-User-Styles.
        return.
      end.
      
      if xls-ctrl-styles = 1
      then do:
        xls-ctrl-styles = 2.
        run Excel-User-Styles.
        put stream str-excel unformatted " </Styles>" skip(1).
      end.
    
    END PROCEDURE.
    
    /* -------------------------------------------------------------------------- */
    
    PROCEDURE Excel-User-Colors:
    
      def var n as int.
      
      /* --- Limpa cores comuns --- */
    
      &scoped-define cores 000000,FFFFFF,FF0000,00FF00,0000FF,FF00FF,FFFF00,00FFFF,808080,969696,C0C0C0,333333,FFFF99
      
      do n = 1 to num-entries("{&cores}"):
        find first t-xls-colors where
                   t-xls-colors.cor = entry(n,"{&cores}") no-error.
    
        if avail t-xls-colors then delete t-xls-colors.
      end.
      
    
      put stream str-excel unformatted
        " <OfficeDocumentSettings "
        "xmlns='urn:schemas-microsoft-com:office:office'>" skip.
        
      if can-find(first t-xls-colors)
      then do:
        put stream str-excel unformatted "  <Colors>" skip.
        
        for each t-xls-colors n = 16 to 31:
          put stream str-excel unformatted
              "   <Color>" skip
              "    <Index>" + trim(string(n,'>9')) + "</Index>" skip
              "    <RGB>#" + t-xls-colors.cor + "</RGB>" skip
              "   </Color>" skip.
        end.
        
        put stream str-excel unformatted "  </Colors>" skip.
      end.
      
      put stream str-excel unformatted
        " </OfficeDocumentSettings>" skip(1)
        " <ExcelWorkbook xmlns='urn:schemas-microsoft-com:office:excel'>" skip
        "  <ProtectStructure>False</ProtectStructure>" skip
        "  <ProtectWindows>False</ProtectWindows>" skip
        " </ExcelWorkbook>" skip(1).
    
    END PROCEDURE.
    
    /* -------------------------------------------------------------------------- */
    
    FUNCTION Excel-End RETURN LOGICAL ():
    
      put stream str-excel unformatted "</Workbook>" skip.
      output stream str-excel close.
      
      return true.
    
    END FUNCTION.
    
    /* ========================================================================== */
    
    FUNCTION Excel-Begin-Sheet RETURN LOGICAL
      (p-name as char, p-cols as char,
       p-header as char, p-footer as char, p-options as char):
    
      def var i  as int.
      def var n  as int.
      def var w  as int.
      def var s  as char.
      def var hr as int.
      def var c  as char.
      def var hd as log.
      
      
      
      xls-sheet-grid = not(lookup(p-options,'NO-GRID',';') > 0).
    
      assign hr = int(Get-Param-Entry(p-header,'HEADER-ROWS','')) no-error.
    
      
      /* --- TRATA CABECALHO / RODAPE --- */
      
      &scoped-define de "PAGS,PAG"
      &scoped-define para "N,P"
      
      xls-header[1] = Get-Param-Entry(p-header,'LEFT','').
      xls-header[2] = Get-Param-Entry(p-header,'CENTER','').
      xls-header[3] = Get-Param-Entry(p-header,'RIGHT','').
    
      xls-footer[1] = Get-Param-Entry(p-footer,'LEFT','').
      xls-footer[2] = Get-Param-Entry(p-footer,'CENTER','').
      xls-footer[3] = Get-Param-Entry(p-footer,'RIGHT','').
      
      do i = 1 to 3:
        do n = 1 to num-entries({&de}):
          xls-header[i] = replace(xls-header[i],
                                  '#' + entry(n,{&de}) + '#',
                                  '&amp;' + entry(n,{&para})).
     
          xls-footer[i] = replace(xls-footer[i],
                                  '#' + entry(n,{&de}) + '#',
                                  '&amp;' + entry(n,{&para})).
        end.
      end.
    
      if not xls-header[1] > ' ' then xls-header[1] = '&amp;F'.
      if not xls-header[2] > ' ' then xls-header[2] = '&amp;A'.
      if not xls-header[3] > ' ' then xls-header[3] = 'ACME Inc.'.
    
      if not xls-footer[1] > ' ' then xls-footer[1] = '&amp;D &amp;T'.
      if not xls-footer[2] > ' ' then xls-footer[2] = ''.
      if not xls-footer[3] > ' ' then xls-footer[3] = '&amp;P / &amp;N'.
    
      
      if xls-ctrl-styles < 2 then run Excel-Styles.
      if xls-ctrl-styles < 2 then run Excel-Styles.
    
      put stream str-excel unformatted
        " <Worksheet ss:Name='" + p-name + "'>" skip
        
        "  <Names>" skip
        "   <NamedRange ss:Name='Print_Titles' " +
        "ss:RefersTo=~"='" + p-name + "'!R1" + 
         (if hr > 1 and hr < 10 then ':R' + string(hr,'9') else '') + "~"/>"
        
        "  </Names>" skip(1)
        
        "  <Table x:FullColumns='1' x:FullRows='1'>" skip(1).
        
    
      xls-cols-count = num-entries(p-cols,';').
        
      do i = 1 to xls-cols-count:
      
        c = entry(i,p-cols,';') + ',,,,,,'.
      
        w = ?.
        assign w = int(entry(1,c)) no-error.
        if w = ? or error-status:error or w < 1 then w = 50.
        
        s = trim(entry(2,c)).
        if s = 'hidden' then s = ''.
        
        hd = (lookup('hidden',c) > 0).
      
        put stream str-excel unformatted
          "   <Column " + 
          (if hd then "ss:Hidden='1' " else "") +
          (if s > ' ' then "ss:StyleID='" + s + "' " else "") +
          "ss:Width='" + trim(string(w,'>>>>>9')) + "'/>" skip.
      end.
      
      put stream str-excel unformatted skip.
      xls-cell-count = ?.
      
      return true.
    
    END FUNCTION.
    
    FUNCTION Excel-End-Sheet RETURN LOGICAL (p-landscape as log, p-scale as int):
    
      if xls-header[1] = '?' then xls-header[1] = ''.
      if xls-header[2] = '?' then xls-header[2] = ''.
      if xls-header[3] = '?' then xls-header[3] = ''.
    
      if xls-footer[1] = '?' then xls-footer[1] = ''.
      if xls-footer[2] = '?' then xls-footer[2] = ''.
      if xls-footer[3] = '?' then xls-footer[3] = ''.
    
    
    
      if p-scale = ? or p-scale <= 0 then p-scale = 100.
      
      if xls-cell-count <> ?
      then put stream str-excel unformatted "   </Row>" skip.
    
      put stream str-excel unformatted
        "  </Table>" skip(1)
        
        "  <WorksheetOptions xmlns='urn:schemas-microsoft-com:office:excel'>" skip
    
        "   <PageSetup>" skip
        "    <Layout" +
         (if p-landscape then " x:Orientation='Landscape'" else "") + 
         " x:CenterHorizontal='1'/>" skip.
         
      if xls-header[1] > ' ' or xls-header[2] > ' ' or xls-header[3] > ' '
      then put stream str-excel unformatted
                      "    <Header x:Margin='0.35' "
                      "x:Data='&amp;L" xls-header[1]
                      "&amp;C" xls-header[2]
                      "&amp;R" xls-header[3] "'/>" skip.
    
      if xls-footer[1] > ' ' or xls-footer[2] > ' ' or xls-footer[3] > ' '
      then put stream str-excel unformatted
             "    <Footer x:Margin='0.35' "
             "x:Data='&amp;L" xls-footer[1]
                     "&amp;C" xls-footer[2]
                     "&amp;R" xls-footer[3] "'/>" skip.
        
      put stream str-excel unformatted
        "    <PageMargins x:Bottom='0.6' x:Left='0.43' "
        "x:Right='0.43' x:Top='0.55'/>" skip
        "   </PageSetup>" skip(1)
        
        "   <Print>" skip
        trim(if xls-sheet-grid then '    <Gridlines/>' else '') skip
        "    <PaperSizeIndex>9</PaperSizeIndex>" skip
        "    <Scale>" + trim(string(p-scale,'>>>9')) + "</Scale>" skip
        "   </Print>" skip(1)
        "   <Selected/>" skip
        
        trim(if xls-sheet-grid then '' else '   <DoNotDisplayGridlines/>') skip
        
        "   <ProtectObjects>False</ProtectObjects>" skip
        "   <ProtectScenarios>False</ProtectScenarios>" skip
        "  </WorksheetOptions>" skip
        " </Worksheet>" skip.
    
      return true.
    
    END FUNCTION.      
    
    /* ========================================================================== */
    
    FUNCTION Excel-Cell-Full RETURN LOGICAL
      (p-type  as char, p-data as char, p-style as char):
    
      def var dt as date initial ?.
      
      
      if p-type = 'Date'
      then do:
        assign dt = date(p-data) no-error.
        p-data = (if dt = ? or error-status:error
                  then ''
                  else string(year(dt),'9999') + '-' + 
                       string(month(dt),'99')  + '-' + string(day(dt),'99')).
      end.
      
      
      if xls-cell-count = ? or xls-cell-count >= xls-cols-count
      then do:
        if xls-cell-count <> ?
        then put stream str-excel unformatted "   </Row>" skip.
        
        put stream str-excel unformatted "   <Row>" skip.
        xls-cell-count = 0.
      end.
    
      put stream str-excel unformatted
        "    <Cell" + 
        (if xls-merge > 1
         then " ss:MergeAcross='" + trim(string(xls-merge - 1,'>>9')) + "'"
         else '') +
        
        (if trim(p-style) > ' '
         then " ss:StyleID='" + trim(p-style) + "'"
         else if p-type = 'Date'
              then " ss:StyleID='Data'"
              else "") +
         
        (if entry(1,p-data,':') = 'Formula' and num-entries(p-data,':') > 1
         then " ss:Formula=~"=" + trim(substr(p-data,9)) + "~""
         else '') + ">"
         
        (if p-type = 'Date' and not p-data > ' '
         then ''
         else "<Data ss:Type='" + trim(replace(p-type,'Date','DateTime')) + "'>" +
              (if entry(1,p-data,':') = 'Formula' and num-entries(p-data,':') > 1
              then '' else trim(p-data)) + "</Data>")
    
        "</Cell>" skip.
    
    
    
      if xls-merge > 1
      then assign xls-cell-count = xls-cell-count + xls-merge
                  xls-merge = 0.
    
      else xls-cell-count = xls-cell-count + 1.
      
      return true.
      
    END FUNCTION.
    
    FUNCTION Excel-Cell RETURN LOGICAL (p-data as char):
    
      Excel-Cell-Full('String', p-data, '').
      return true.
    
    END FUNCTION.
    
    FUNCTION Excel-Cells RETURN LOGICAL (p-cells as char):
    
      def var i as int.
      
      do i = 1 to num-entries(p-cells,'|'):
        Excel-Cell-Full('String', entry(i,p-cells,'|'), '').
      end.
      
      return true.
    
    END FUNCTION.
    
    FUNCTION Excel-Cell-Char RETURN LOGICAL (p-data as char, p-style as char):
    
      Excel-Cell-Full('String', p-data, p-style).
      return true.
    
    END FUNCTION.
    
    FUNCTION Excel-Cell-Int RETURN LOGICAL (p-data as int, p-style as char):
    
      Excel-Cell-Full('Number', trim(string(p-data,'->>>>>>>>>>>9')), p-style).
      return true.
    
    END FUNCTION.
    
    FUNCTION Excel-Cell-Dec RETURN LOGICAL (p-data as dec, p-style as char):
      
      Excel-Cell-Full('Number',
        replace(trim(string(p-data,'->>>>>>>>>>>9.9999')),',','.'), p-style).
      
      return true.
    
    END FUNCTION.
    
    FUNCTION Excel-Cell-Date RETURN LOGICAL (p-data as date, p-style as char):
    
      Excel-Cell-Full('Date', string(p-data,'99/99/9999'), p-style).
      return true.
    
    END FUNCTION.
    
    FUNCTION Excel-Merge return logical (cells as int):
      if cells > 1 then xls-merge = cells.
      return true.
    END FUNCTION.
    
    
    /* ========================================================================== */
    
    FUNCTION Style-Get RETURN LOG (p-id as char):
    
      find t-xls-styles where t-xls-styles.id = p-id no-error.
      return avail t-xls-styles.
    
    END FUNCTION.
    
    FUNCTION Style-Get-Attr RETURN LOG
      (p-id as char, p-tipo as char, p-subtipo as char):
      
      find first t-xls-attr where
                 t-xls-attr.id = p-id and
                 t-xls-attr.tipo = p-tipo and
                 t-xls-attr.subtipo = p-subtipo
                 no-error.
                 
      return avail t-xls-attr.
    
    END FUNCTION.
    
    FUNCTION Style-Add RETURN LOG (p-id as char):
    
      if Style-Get(p-id) then return false.
      
      create t-xls-styles.
      assign t-xls-styles.id = p-id
             t-xls-styles.padrao = (p-id = 'Default').
    
    END FUNCTION.
    
    FUNCTION Style-Copy RETURN LOG (from-style as char, to-style as char):
    
      def var v-padrao as log.
    
      if not Style-Get(from-style) then return false.
      v-padrao = t-xls-styles.padrao.
      
      if not Style-Get(to-style) then Style-Add(to-style).
      t-xls-styles.padrao = v-padrao.
      
      for each t-xls-attr where t-xls-attr.id = to-style:
        delete t-xls-attr.
      end.
    
      for each t-xls-attr where t-xls-attr.id = from-style:
        create b-xls-attr.
        
        buffer-copy t-xls-attr except t-xls-attr.id to b-xls-attr
             assign b-xls-attr.id = to-style.
      end.
    
    END FUNCTION.
    
    FUNCTION Style-Attr RETURN LOG
      (p-id as char, p-tipo as char, p-subtipo as char,
       p-attr1 as char, p-attr2 as char, p-attr3 as char,
       p-attr4 as char, p-attr5 as char, p-attr6 as char):
    
      def var i as int.
      if not Style-Get(p-id) then return false.
    
      for each t-xls-attr where
               t-xls-attr.id = p-id and
               t-xls-attr.tipo = p-tipo and
               t-xls-attr.subtipo = p-subtipo:
        delete t-xls-attr.
      end.
      
      create t-xls-attr.
      assign t-xls-attr.id = p-id
             t-xls-attr.tipo = p-tipo
             t-xls-attr.subtipo = p-subtipo
             t-xls-attr.attrs[1] = p-attr1  t-xls-attr.attrs[2] = p-attr2
             t-xls-attr.attrs[3] = p-attr3  t-xls-attr.attrs[4] = p-attr4
             t-xls-attr.attrs[5] = p-attr5  t-xls-attr.attrs[6] = p-attr6.
    
    END FUNCTION.
    
    /* -------------------------------------------------------------------------- */
    
    FUNCTION Build-Put-Attr RETURN CHAR (name as char, attrs as char):
    
      def var i as int.
      def var c as char.
    
      do i = 1 to num-entries(attrs):
        c = c + " ss:" + entry(i,attrs) + "='" + t-xls-attr.attrs[i] + "'".
      end.
      
      return "   <" + name + c + "/>".
      
    END FUNCTION.
    
    PROCEDURE Excel-User-Styles:
    
      def var i as int.
    
      for each t-xls-styles by t-xls-styles.padrao desc by t-xls-styles.id:
      
        if not can-find(first t-xls-attr where t-xls-attr.id = t-xls-styles.id)
        then next.
    
        put stream str-excel unformatted
            "  <Style ss:ID='" + t-xls-styles.id + 
                   "' ss:Name='" + 
                      (if t-xls-styles.id = 'Default'
                       then 'Normal' else t-xls-styles.id) + "'>" skip.
                   
        if Style-Get-Attr(t-xls-styles.id, 'Interior', '')
        then put stream str-excel unformatted
                 "   <Interior ss:Color='#" + t-xls-attr.attrs[1] + 
                 "' ss:Pattern='Solid'/>" skip.
    
        if Style-Get-Attr(t-xls-styles.id, 'Alignment', '')
        then put stream str-excel unformatted
                 Build-Put-Attr('Alignment','Horizontal,Vertical,WrapText') skip.
    
        if Style-Get-Attr(t-xls-styles.id, 'Font', '')
        then put stream str-excel unformatted
                 Build-Put-Attr('Font','FontName,Size,Color,Bold,Italic') skip.
    
        if Style-Get-Attr(t-xls-styles.id, 'NumberFormat', '')
        then put stream str-excel unformatted
                 Build-Put-Attr('NumberFormat','Format') skip.
    
        if can-find(first t-xls-attr where
                          t-xls-attr.id = t-xls-styles.id and
                          t-xls-attr.tipo = 'Border')
        then do:
          &scoped-define border-pos entry(i,"Top,Bottom,Left,Right")
          put stream str-excel unformatted "   <Borders>" skip.
          
          do i = 1 to 4:
            if Style-Get-Attr(t-xls-styles.id,'Border', {&border-pos})
            then put stream str-excel unformatted
                     ' ' Build-Put-Attr('Border','Position,Weight,LineStyle') skip.
          end.
    
          put stream str-excel unformatted "   </Borders>" skip.
        end.
                   
        put stream str-excel unformatted "  </Style>" skip(1).
      end.
      
      empty temp-table t-xls-styles.
      empty temp-table t-xls-attr.
    
    END PROCEDURE.
    
    FUNCTION Style-New-Color RETURN LOG(p-color as char):
    
      if not can-find(first t-xls-colors where t-xls-colors.cor = p-color)
      then do:
        create t-xls-colors.
        assign t-xls-colors.cor = p-color.
      end.
      
      return true.
    
    END FUNCTION.
    
    /* -------------------------------------------------------------------------- */
    
    FUNCTION Style-Border RETURN LOG (id as char, pos as char, weight as int):
    
      def var i as int.
    
      &scoped-define param string(weight),'Continuous','','',''
      if pos = 'All' then pos = 'Top,Bottom,Left,Right'.
      
      do i = 1 to num-entries(pos):
        Style-Attr(id,'Border',entry(i,pos),entry(i,pos),{&param}).
      end.
    
      return true.
      
    END FUNCTION.
    
    FUNCTION Style-Interior RETURN LOG (id as char, p-color as char):
    
      Style-New-Color(p-color).
      return Style-Attr(id,'Interior','',trim(caps(p-color)),'','','','','').
    
    END FUNCTION.
    
    FUNCTION Style-Align RETURN LOG
      (id as char, halign as char, valign as char, wrap as log):
      
      return Style-Attr(id,'Alignment','',
                        halign,valign,string(wrap,'1/0'),'','','').
    END FUNCTION.
    
    FUNCTION Style-Font RETURN LOG
      (id as char, name as char, p-size as int, p-color as char,
       bold as log, italic as log):
    
      Style-New-Color(p-color).
      return Style-Attr(id,'Font','', name, string(p-size), '#' + p-color,
                        string(bold,'1/0'), string(italic,'1/0'), '').
    END FUNCTION.
    
    FUNCTION Style-Number RETURN LOG (id as char, formato as char):
      return Style-Attr(id,'NumberFormat','',formato,'','','','','').
    END FUNCTION.
    
    /* -------------------------------------------------------------------------- */
    
    PROCEDURE Style-Default:
    
      empty temp-table t-xls-styles.
      empty temp-table t-xls-attr.  
     
      Style-Add('Default').
      Style-Font('Default','Tahoma',10,'000000',false,false).
      Style-Number('Default',
                   "_(* #,##0.00_);_(* \(#,##0.00\);_(* &quot;-&quot;??_);_(@_)").
    
      Style-Copy('Default','Porcent').
      Style-Number('Porcent','0%').
      
      Style-Copy('Default','NumInt').
      Style-Number('NumInt','0').
    
      Style-Copy('Default','Data').
      Style-Number('Data', 'dd/mm/yyyy').
    
    END PROCEDURE.
    
  2. willians.ambrosio

    willians.ambrosio Sem Pontuação

    Poderia mandar um programa de excemplo?
  3. mcarril

    mcarril Membro Participativo

    Só para informação e complementação:

    Para quem quiser um arquivo comum para abrir no EXCEL, é só gerar os dados delimitados por um identificador.
    Aqui no caso utilizamos o ";" e se a extensão do arquivo for criada com .csv, o excel abre e converte as colunas automaticamente.
  4. mcarril

    mcarril Membro Participativo

    Só para informação e complementação:

    Para quem quiser um arquivo comum para abrir no EXCEL, é só gerar os dados delimitados por um identificador.
    Aqui no caso utilizamos o ";" e se a extensão do arquivo for criada com .csv, o excel abre e converte as colunas automaticamente.
  5. jalegria

    jalegria Membro Participativo

    Saudações...

    O objetivo não é gerar um csv, isso é simples e largamente utilizado por quem trabalha no ambiente caracter, e as vezes até no gráfico. Essa include é para quem trabalha com caracter e fica limitado na hora de gerar algo um pouco mais avançado que um csv ou um relatorio em formato texto.

    Ela gera um arquivo XML com a sintaxe padrão do Excel 2003 ou superior.
    Segue um exemplo simples de utilização.

    Qualquer dúvida estou a disposição...

    Código:
    {excel.i}
    run Planilha('./teste.xml').
    
    PROCEDURE Planilha:
    
      def input param arq as char.
      def var i as int.
    
    
      Excel-Begin(arq, '').
      run Estilos.
    
      Excel-Begin-Sheet('Teste',
                        '100;200;250;70;40;80;80',
                        'LEFT=;CENTER=TESTE DE PLANILHA EXCEL' +
                        ';RIGHT=;HEADER-ROWS=4', '', '').
      Excel-Merge(2).
      Excel-Cell-Char('ACME INC.', 'Cabec1').      
    
      Excel-Merge(5).
      Excel-Cell-Char('Relatorio de Testes ' +
                       string(month(today),'99') + '/' + 
                       string(year(today),'9999'), 'Cabec2').
      Excel-Merge(7).
      Excel-Cell-Char('','Cabec2').
    
      Excel-Merge(3).
      Excel-Cell-Char('Elaborado por: Nome do usuario', 'Cabec').
      
      Excel-Merge(4).
      Excel-Cell-Char('Emitido em ' + string(today,'99/99/9999') + 
                      ' ' + string(time,'HH:MM:SS'), 'Cabec3').
    
      
      &scoped-define labels 'CNPJ,Nome,Endereco,Emissao,Qtde,Valor Unit.,Valor'
      
      do i = 1 to num-entries({&labels}):
        Excel-Cell-Char(entry(i, {&labels}), 'Label').
      end.
    
      do i = 1 to 100:
        Excel-Cell('99.999.999/9999-99').
        Excel-Cell(trim(fill('Teste ', random(1,5)))).
        Excel-Cell(trim(fill('Teste ', random(3,6)))).
        Excel-Cell-Date(today + i, '').
        Excel-Cell-Int(random(1,10), 'NumInt').
        Excel-Cell-Dec(dec(random(10, 100)), '').
        Excel-Cell-Full('Number', 'Formula:RC[-2]*RC[-1]', '').
      end.
    
      Excel-End-Sheet(true, 95).
      Excel-End().
    
    END PROCEDURE.
    
    
    PROCEDURE Estilos:
    
      Style-Font('Default','Calibri', 10, '000000', false, true).
      Style-Border('Default','',1).
    
      Style-Font('Data','Calibri', 10, '000000', false, true).
      Style-Font('NumInt','Calibri', 10, '000000', false, true).
    
      Style-Add('Cabec').                       
      Style-Interior('Cabec','CCFFCC').
      Style-Font('Cabec','Calibri',10,'000000',false,true).
      Style-Align('Cabec','Left','Bottom',false).
      
      Style-Copy('Cabec','Cabec1').
      Style-Font('Cabec1','Calibri',12,'000000',true,FALSE).
    
      Style-Copy('Cabec','Cabec2').
      Style-Align('Cabec2','Left','Bottom',false).
      Style-Font('Cabec2','Calibri',11,'000000',true,false).
      
      Style-Border('Cabec','Bottom',1).
    
      Style-Copy('Cabec','Cabec3').
      Style-Align('Cabec3','Right','Bottom',false).
    
      Style-Copy('Default','Label').
      Style-Interior('Label','DDDDDD').
      Style-Align('Label','Center','Center',true).
      Style-Border('Label','Bottom',1).
     
    END PROCEDURE.
    
  6. Parrillo

    Parrillo Sem Pontuação

    Desculpe desenterrar o tópico.. :oops:

    Mas é que foi de excelente ajuda para mim e gostaria de agradecer o autor..

    Parabéns mesmo..

    Se puder colocar mais algum (ou alguns) exemplos de formatação agradeço demais..

    Excemplo: Colunas com Filtros, Congelar Painel, etc...

    Muito obrigado Jefferson....

Compartilhe esta Página