ALIAS CI_DRE
// a Variavel z_Recno guarda a posicao do registro do arquivo mestre do relatorio
VARIAVEL znil := ci_dre->(DbGoto(z_Recno))
VARIAVEL zModeloXLS := 'ci_dre.xls'
VARIAVEL cAaMm := ''
VARIAVEL zfNumS := 0
VARIAVEL zCrNumDupS := ''
VARIAVEL zCrDtVencS := ''
VARIAVEL zPlanilhaResultante := ''
VARIAVEL zfTxDesconto := 0
VARIAVEL zDadosDaObra := ""
VARIAVEL zkk := 0
VARIAVEL zbl := {|cColLine| left(cColLine,1) + lTrim(Str( Val(SubStr(cColLine,2))+zkk,4)) }
VARIAVEL oFileComSheets_Modelo := ''
VARIAVEL oSheet_Modelo := ''

VARIAVEL #TEXTO_FONTE
   Private zoProgressBar, zCmdsDurante, zCmdsDepois, zl:=0, zMaxLines:=33, zPages:=1, zPagesImpressas:=0, zAditivo, zStatus, vOpcoes, wOpt:=1, oClasse, zaLines:={}, zCodCli
   
   debugalert('vai ativar excel...')
   oClasse := tCvXls():New()
   debugalert('vai exibir excel...')
   oClasse:oXls:Visible := .t.
   debugalert('exibiu excel...')

   cAaMm := SubStr( Dtos(s_datual), 3, 4)
   
   if .not. oClasse:AddSheet( zModeloXLS, zPlanilhaResultante )
      Alert("Nao consegui abrir modelo de fatura "+zModeloXLS,,"R/W")
      Return .f.
   endif


   oClasse:oSheet:Cells( nRow, nColPos ):Value:=uValue


   oClasse:Cell( 'C19' , frgs( oClasse:Cell('C19') )
   oClasse:Cell( 'C20' , frgs('E1D1G2') )

   oClasse:Cell( 'C20' , frgs('E1D1G2') )

   // fr('DD001',,'G1','PAGAS')
   
         // cKey1 := 'DD'+ SubStr(cOldKey,2,3)
         // cKey2 := 'S'+ SubStr(cOldKey,5,5)
         // cKey3 := 'G'+ SubStr(cOldKey,10,1)
         // cKey4 := 'PAGAS'
         // cKey5 := 'CTA'+SubStr(cOldKey,11,4)
         // cKey  := cAaaaMm + pad(cKey1,10)+pad(cKey2,10)+pad(cKey3,10)+pad(cKey4,20)+pad(cKey5,10)



      
         oClasse:Cell( eVal(zbl,"c15"), RemoverAcentos(AllTrim(sccrcli->Cr_Nome), 'ANSI') )
         oClasse:Cell( eVal(zbl,"c16"), RemoverAcentos(sccrcli->(AllTrim(Cr_Rua)+" "+cr_NumRua), 'ANSI') )
         oClasse:Cell( eVal(zbl,"m16"), RemoverAcentos(AllTrim(sccrcli->Cr_Bairro), 'ANSI') )
      
         oClasse:Cell( eVal(zbl,"c17"), AllTrim(sccrcli->Cr_email) )
         oClasse:Cell( eVal(zbl,"n17"), AllTrim(sccrcli->Cr_Cep) )
         oClasse:Cell( eVal(zbl,"c18"), AllTrim(sccrcli->Cr_Cidade) )
         oClasse:Cell( eVal(zbl,"h18"), AllTrim(sccrcli->Cr_uf) )
         oClasse:Cell( eVal(zbl,"m18"), AllTrim(sccrcli->Cr_fone) )
      
         oClasse:Cell( eVal(zbl,"c19"), AllTrim(sccrcli->Cr_cgc) )
         oClasse:Cell( eVal(zbl,"k19"), AllTrim(sccrcli->Cr_insc_es) )
      
         // oClasse:Cell( eVal(zbl,"i29"), StrZero(zCodCli,6) )
         // oClasse:Cell( eVal(zbl,"k29"), zCrNumDupS )
         oClasse:Cell( eVal(zbl,"l24"), zCrDtVencS )
   
         DbSelectArea("ci_dremv")
         Do While .not. eof() .and. fnums=zfNumS
            oClasse:Cell( eVal(zbl,"b"+lTrim(Str(28+zl,4))),    "NFS"+lTrim(Str(mfNum,10)) )
            oClasse:Cell( eVal(zbl,"c"+lTrim(Str(28+zl,4))),    lTrim(Str(mQuant,10)) )
            oClasse:Cell( eVal(zbl,"d"+lTrim(Str(28+zl,4))),    AllTrim(Se_prod->( DbSeek(ci_dremv->pCod), pDesc)) )
            oClasse:Cell( eVal(zbl,"i"+lTrim(Str(28+zl,4))),    if(mfges="E","DEVOLVIDO",if(mfges="M","RELOCADO","LOCADO") ) )
            oClasse:Cell( eVal(zbl,"j"+lTrim(Str(28+zl,4))),    AllTrim(pObs) )
            oClasse:Cell( eVal(zbl,"k"+lTrim(Str(28+zl,4))),    lTrim(Str(pDiasLoca,10)) )
            oClasse:Cell( eVal(zbl,"l"+lTrim(Str(28+zl,4))),    oClasse:Val(ci_dremv->pValLoca) )
            skip
            if ++zl > zMaxLines
               exit
            endif
         enddo
         DbSelectArea('ci_dre')

         // oClasse:Cell("m29", oClasse:Val(zfTxDesconto) )
      
         oClasse:Cell( eVal(zbl,"c63"), zDadosDaObra )

         ++zPagesImpressas
         zkk += 74
         zl:=1
      enddo

      DebugAlert('vai oClasse:oXls:ActiveWorkbook:Save()')
      oClasse:oXls:ActiveWorkbook:Save()

      if wOpt=1
         exit
      endif
      DbSkip()
   
   enddo

   DebugAlert('vai oClasse:oXls:PrintPreview()')
   oClasse:oXls:ActiveWorkbook:PrintPreview()
   
   // DebugAlert('vai oClasse:oXls:Workbooks:Close()')
   // oClasse:oXls:Workbooks:Close()  
   // DebugAlert('Vai Encerrar Excel com oClasse:oXls:Quit()')
   // oClasse:oXls:Quit() 
   // DebugAlert('Encerrou  Excel com oClasse:oXls:Quit()')

   DbSelectArea('ci_dre')
   debugalert('4')
 
#FIM_TEXTO_FONTE