Bom dia pessoal, Preciso fazer um progrma que gere um relatório com dados e valores, e mostre um gráfico dos dados gerados. Por exemplo: relatório de faturamento por canal de venda, onde cada canal vai ter seu faturamento e esse valor será representado num gráfico de pizza. Como eu faço a parte de exportar para o excel? :shock:
Tem um exemplo desta planilha? vc vai jogar os dados no excel e depois gerar o grafico? se for isso é simples..
O que preciso fazer é gerar os dados do fatutamento em um excel, pela quebra selecionada e gerar um gráfico. Segue o programa como está: {utp/ut-glob.i} def var h-acomp as handle no-undo. def var c-destino as char no-undo. def var h-wprog as handle no-undo. def var chExcel as com-handle no-undo. /*HANDLE DA APLICA€ÇO EXCEL */ /* definicao das temp-tables para recebimento de parametros */ define temp-table tt-param no-undo field destino as integer field arquivo as char format "x(35)" field usuario as char format "x(12)" field data-exec as date field hora-exec as integer field classifica as integer field desc-classifica as char format "x(40)" field modelo-rtf as char format "x(35)" field l-habilitaRtf as LOG field cod-estabel-ini like nota-fiscal.cod-estabel field cod-estabel-fin like nota-fiscal.cod-estabel field dt-emis-nota-ini like nota-fiscal.dt-emis-nota field dt-emis-nota-fin like nota-fiscal.dt-emis-nota field nome-abrev-ini like emitente.nome-abrev field nome-abrev-fin like emitente.nome-abrev field cod-gr-cli-ini like gr-cli.cod-gr-cli field cod-gr-cli-fin like gr-cli.cod-gr-cli field repres-nome-abrev-ini like repres.nome-abrev field repres-nome-abrev-fin like repres.nome-abrev field cod-canal-venda-ini like canal-venda.cod-canal-venda field cod-canal-venda-fin like canal-venda.cod-canal-venda field it-codigo-ini like item.it-codigo field it-codigo-fin like item.it-codigo field fm-cod-com-ini like item.fm-cod-com field fm-cod-com-fin like item.fm-cod-com . define temp-table tt-relatorio no-undo field cod-canal-venda like nota-fiscal.cod-canal-venda field cod-rep like repres.cod-rep field fm-cod-com like item.fm-cod-com field cod-emitente like emitente.cod-emitente field vl-faturamento like nota-fiscal.vl-tot-nota field vl-total like nota-fiscal.vl-tot-nota field vl-canal like nota-fiscal.cod-canal-venda field desc-canal as char format "x(35)" field descricao as char format "x(35)". define temp-table tt-digita no-undo field cod-canal-venda as integer field fm-cod-com as char format "x(10)" field nome as char format "x(35)" field i-tipo as integer format ">9" field lg-informa as logical init yes index id cod-canal-venda. define temp-table tt-canal no-undo field cod-canal-venda as integer index id cod-canal-venda. define temp-table tt-gr-cli no-undo field cod-gr-cli as integer index id cod-gr-cli . define temp-table tt-emitente no-undo field cod-emitente as integer index id cod-emitente. define temp-table tt-repres no-undo field cod-rep as integer index id cod-rep. define temp-table tt-fam-comerc no-undo field fm-cod-com as char index id fm-cod-com. define temp-table tt-item no-undo field it-codigo as char index id it-codigo. define temp-table tt-raw-digita field raw-digita as raw. define buffer b-tt-digita for tt-digita. /* recebimento de parametros */ def input parameter raw-param as raw no-undo. def input parameter table for tt-raw-digita. create tt-param. raw-transfer raw-param to tt-param. for each tt-raw-digita no-lock: create tt-digita. raw-transfer tt-raw-digita.raw-digita to tt-digita. end. for each tt-digita no-lock: if i-tipo = 1 then do: create tt-canal. raw-transfer tt-raw-digita.raw-digita to tt-canal. end. if i-tipo = 2 then do: create tt-gr-cli. raw-transfer tt-raw-digita.raw-digita to tt-gr-cli. end. if i-tipo = 3 then do: create tt-emitente. raw-transfer tt-raw-digita.raw-digita to tt-emitente. end. if i-tipo = 4 then do: create tt-repres. raw-transfer tt-raw-digita.raw-digita to tt-repres. end. if i-tipo = 5 then do: create tt-fam-comerc. raw-transfer tt-raw-digita.raw-digita to tt-fam-comerc. end. if i-tipo = 6 then do: create tt-item. raw-transfer tt-raw-digita.raw-digita to tt-item. end. end. find first tt-param no-lock no-error. /* include padrao para variaveis de relatorio*/ {include/i-rpvar.i} find first param-global no-lock no-error. ASSIGN c-programa = "RS000x":U c-versao = "2.00":U c-revisao = "06.000":U c-empresa = param-global.grupo c-sistema = "xxxxxxxx" c-titulo-relat = "Relatório e Gráficos de Faturamento por Canal de Venda". run utp/ut-acomp.p persistent set h-acomp. run pi-inicializar in h-acomp ("Inicializando..."). /* --- gera o relatório --- */ {include/i-rpout.i} /* Include padrao para output de relatorios */ /* VIEW FRAME f-cabec. */ /* VIEW FRAME f-rodape. */ /* início do relatório */ for each tt-relatorio: delete tt-relatorio. end. find first tt-canal no-lock no-error. find first tt-emitente no-lock no-error. find first tt-gr-cli no-lock no-error. find first tt-repres no-lock no-error. find first tt-fam-comerc no-lock no-error. find first tt-item no-lock no-error. for each nota-fiscal where nota-fiscal.emite-duplic = yes and nota-fiscal.dt-cancela = ? and nota-fiscal.cod-estabel >= tt-param.cod-estabel-ini and nota-fiscal.cod-estabel <= tt-param.cod-estabel-fin and nota-fiscal.dt-emis-nota >= tt-param.dt-emis-nota-ini and nota-fiscal.dt-emis-nota <= tt-param.dt-emis-nota-fin and nota-fiscal.cod-canal-venda >= tt-param.cod-canal-venda-ini and nota-fiscal.cod-canal-venda <= tt-param.cod-canal-venda-fin no-lock: if can-find(first tt-canal) then if not can-find(first tt-canal where tt-canal.cod-canal-venda = nota-fiscal.cod-canal-venda) then next. find emitente where emitente.cod-emitente = nota-fiscal.cod-emitente and emitente.nome-abrev >= tt-param.nome-abrev-ini and emitente.nome-abrev <= tt-param.nome-abrev-fin no-lock. if can-find(first tt-emitente) then if not can-find(first tt-emitente where tt-emitente.cod-emitente = emitente.cod-emitente) then next. find gr-cli where gr-cli.cod-gr-cli = emitente.cod-gr-cli and gr-cli.cod-gr-cli >= tt-param.cod-gr-cli-ini and gr-cli.cod-gr-cli <= tt-param.cod-gr-cli-fin no-lock. if can-find(first tt-gr-cli) then if not can-find(first tt-gr-cli where tt-gr-cli.cod-gr-cli = gr-cli.cod-gr-cli) then next. find repres where repres.cod-rep = nota-fiscal.cod-rep and repres.nome-abrev >= tt-param.repres-nome-abrev-ini and repres.nome-abrev <= tt-param.repres-nome-abrev-fin no-lock. if can-find(first tt-repres) then if not can-find(first tt-repres where tt-repres.cod-rep = repres.cod-rep) then next. for each it-nota-fisc where it-nota-fisc.nr-nota-fis = nota-fiscal.nr-nota-fis and it-nota-fisc.serie = nota-fiscal.serie and it-nota-fisc.cod-estabel = nota-fiscal.cod-estabel and it-nota-fisc.it-codigo >= tt-param.it-codigo-ini and it-nota-fisc.it-codigo <= tt-param.it-codigo-fin and it-nota-fisc.it-codigo = tt-item.it-codigo no-lock: find item where item.it-codigo = it-nota-fisc.it-codigo and item.fm-cod-com >= tt-param.fm-cod-com-ini and item.fm-cod-com <= tt-param.fm-cod-com-fin no-lock. if can-find(first tt-fam-comerc) then if not can-find(first tt-fam-comerc where tt-fam-comerc.fm-cod-com = item.fm-cod-com) then next. if avail item then do: create tt-relatorio. assign tt-relatorio.cod-canal-venda = nota-fiscal.cod-canal-venda tt-relatorio.cod-rep = repres.cod-rep tt-relatorio.fm-cod-com = item.fm-cod-com tt-relatorio.cod-emitente = emitente.cod-emitente. MESSAGE tt-relatorio.cod-canal-venda tt-relatorio.cod-rep tt-relatorio.fm-cod-com tt-relatorio.cod-emitente VIEW-AS ALERT-BOX INFO BUTTONS OK. end. end. end. /* fim do bloco 1 for each*/ /* =============== filtrando por classificação ================================= */ MESSAGE "classificação: " tt-param.classif VIEW-AS ALERT-BOX INFO BUTTONS OK. if can-find(first tt-relatorio) then do: if tt-param.classifica = 1 /* Canal de Vendas*/ then assign tt-relatorio.vl-total = 0. for each tt-relatorio break by tt-relatorio.cod-canal-venda: if first-of (tt-relatorio.cod-canal-venda) then do: assign tt-relatorio.vl-faturamento = 0. find canal-venda where tt-relatorio.cod-canal-venda = canal-venda.cod-canal-venda no-lock no-error. if avail canal-venda then assign tt-relatorio.descricao = canal-venda.descricao. end. assign tt-relatorio.vl-faturamento = tt-relatorio.vl-faturamento + nota-fiscal.vl-tot-nota tt-relatorio.vl-total = tt-relatorio.vl-total + tt-relatorio.vl-faturamento. /* display tt-relatorio.descricao */ /* tt-relatorio.vl-faturamento. */ run pi-csv. end. /* --------------------------------------------------------------- */ if tt-param.classif = 2 /* Representante*/ then assign tt-relatorio.vl-total = 0. for each tt-relatorio break by tt-relatorio.cod-rep: if first-of (tt-relatorio.cod-rep) then do: assign tt-relatorio.vl-faturamento = 0. find repres where tt-relatorio.cod-rep = repres.cod-rep no-lock no-error. if avail canal-venda then assign tt-relatorio.descricao = repres.nome-abrev. end. assign tt-relatorio.vl-faturamento = tt-relatorio.vl-faturamento + nota-fiscal.vl-tot-nota tt-relatorio.vl-total = tt-relatorio.vl-total + tt-relatorio.vl-faturamento. display tt-relatorio.descricao tt-relatorio.vl-faturamento. end. /* --------------------------------------------------------------- */ if tt-param.classif = 3 /* Familia Comercial*/ then assign tt-relatorio.vl-total = 0. for each tt-relatorio break by tt-relatorio.fm-cod-com: if first-of (tt-relatorio.fm-cod-com) then do: assign tt-relatorio.vl-faturamento = 0. find fam-comerc where tt-relatorio.fm-cod-com = fam-comerc.fm-cod-com no-lock no-error. if avail canal-venda then assign tt-relatorio.descricao = fam-comerc.descricao. end. assign tt-relatorio.vl-faturamento = tt-relatorio.vl-faturamento + nota-fiscal.vl-tot-nota tt-relatorio.vl-total = tt-relatorio.vl-total + tt-relatorio.vl-faturamento. display tt-relatorio.descricao tt-relatorio.vl-faturamento. end. /* --------------------------------------------------------------- */ if tt-param.classif = 4 /* Canal de Venda / Cliente*/ then assign tt-relatorio.vl-total = 0. for each tt-relatorio break by tt-relatorio.cod-canal-venda by tt-relatorio.cod-emitente: if first-of (tt-relatorio.cod-canal-venda) then do: assign tt-relatorio.vl-canal = 0. find canal-venda where tt-relatorio.cod-canal-venda = canal-venda.cod-canal-venda no-lock no-error. if avail canal-venda then assign tt-relatorio.desc-canal = canal-venda.descricao. end. if first-of (tt-relatorio.cod-emitente) then do: assign tt-relatorio.vl-faturamento = 0. find emitente where tt-relatorio.cod-emitente = emitente.cod-emitente no-lock no-error. if avail emitente then assign tt-relatorio.descricao = emitente.nome-abrev. end. /*------------------------------------------------------------------------------------------*/ assign tt-relatorio.vl-faturamento = tt-relatorio.vl-faturamento + nota-fiscal.vl-tot-nota tt-relatorio.vl-canal = tt-relatorio.vl-canal + tt-relatorio.vl-faturamento. tt-relatorio.vl-total = tt-relatorio.vl-total + tt-relatorio.vl-canal. /*------------------------------------------------------------------------------------------*/ if last-of (tt-relatorio.cod-emitente) then do: display tt-relatorio.descricao tt-relatorio.vl-faturamento. end. if last-of (tt-relatorio.cod-canal-venda) then do: display tt-relatorio.desc-canal tt-relatorio.vl-canal. end. disp tt-relatorio.vl-total. end. end. /*if can-find*/ {include/i-rpclo.i} run pi-finalizar in h-acomp.
Olá... consegui ajustar o trecho do meu código para gerar o gráfico... segue os comandos caso alguém precise... /* ------------------------------------------------------------------ */ procedure pi-grafico. /* ------------------------------------------------------------------ */ chExcelWorkSheet:Range("A3:B5"):Select. chExcelChart = chExcelWorkSheet:Application:ActiveSheet:Shapes:AddChart(70). chExcelWorkSheet:Application:ActiveSheet:ChartObjects("Gráfico 1"):Activate. chExcelWorkSheet:Application:ActiveChart:ApplyLayout (6). chExcelWorkSheet:Application:ActiveChart:ChartTitle:Select. chExcelWorkSheet:Application:ActiveChart:ChartTitle:Text = "". end procedure.