<?php
     $filename=$xlsf.'.xls';
     
     $file_content='';
     $file_content.='<?php '."\n";
     $file_content.='header("Content-type: application/vnd.ms-excel");'."\n";
//      $file_content.='header("Content-type: application/vnd.ms-excel"); charset=iso-8859-1'."\n";
     $file_content.='header("Content-Disposition: attachment; filename='.$filename.'");'."\n";
     $file_content.='header("Pragma: no-cache");'."\n";
     $file_content.='header("Expires: 0");'."\n";
     
     $file_content.="\n".'?> ';
     $file_content.="\n";

     $file_content.="<style>"."\n";
     /*force text*/     
     $file_content.='.text{mso-number-format:"\@";}'."\n";
     $file_content.='.num {mso-number-format:General;}'."\n";
     $file_content.="</style>"."\n";
     
     
     $domg = new DOMDocument();
          $domg->encoding = 'utf-8';
          $domg->xmlVersion = '1.0';
          $domg->formatOutput = true;
     $ele=$domg;

     
     
     $ttbl='table';
     $trow='tr';
     $tcol='td';
     
     $root=$domg->appendChild($domg->createElement($ttbl));

     $row=$root->appendChild($domg->createElement($trow));     
     $col=$row->appendChild($domg->createElement('th','EMPRESA :'));
     $col=$row->appendChild($domg->createElement($tcol,$empr0['empr_descri']));
     
     $row=$root->appendChild($domg->createElement($trow));     
     $col=$row->appendChild($domg->createElement('th','RUC :'));
     $col=$row->appendChild($domg->createElement($tcol,"'".$empr0['empr_ruc']));
     
     $row=$root->appendChild($domg->createElement($trow));     
     $col=$row->appendChild($domg->createElement('th','MODULO :'));
     $col=$row->appendChild($domg->createElement($tcol,$modu));
     
     $row=$root->appendChild($domg->createElement($trow));     
     $col=$row->appendChild($domg->createElement('th','INFO :'));
     $col=$row->appendChild($domg->createElement($tcol,$info));
     
     $row=$root->appendChild($domg->createElement($trow));     
     $col=$row->appendChild($domg->createElement('th','Fecha 1 :'));
     $col=$row->appendChild($domg->createElement($tcol,$fecha1));
     
     $row=$root->appendChild($domg->createElement($trow));     
     $col=$row->appendChild($domg->createElement('th','Fecha 2 :'));
     $col=$row->appendChild($domg->createElement($tcol,$fecha2));
     if(!empty($enti))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Entidad :'));
          $col=$row->appendChild($domg->createElement($tcol,$enti));
     }
     if(!empty($item))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Item :'));
          $col=$row->appendChild($domg->createElement($tcol,$item));
     }
     
     if(empty($item) and $info=='iikrdx')
     {
//           $row=$root->appendChild($domg->createElement($trow));     
//           $col=$row->appendChild($domg->createElement('th','Item :'));
//           $item=msql_result($zreso,0,'item_hide').' - '.msql_result($zreso,0,'item_descri_hide');
//           $col=$row->appendChild($domg->createElement($tcol,$item));
     }
     
     
     
     if(!empty($ctas))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Cuenta :'));
          $col=$row->appendChild($domg->createElement($tcol,$ctas));
     }
     if(!empty($lsub))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Linea :'));
          $col=$row->appendChild($domg->createElement($tcol,$lsub));
     }
     if(!empty($zsub))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Zona :'));
          $col=$row->appendChild($domg->createElement($tcol,$zsub));
     }
     if(!empty($bode))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Bodega :'));
          $col=$row->appendChild($domg->createElement($tcol,$bode));
     }
     if(!empty($ptoe))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Pto.Emi. :'));
          $col=$row->appendChild($domg->createElement($tcol,$ptoe));
     }
     if(!empty($caja))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Caja :'));
          $col=$row->appendChild($domg->createElement($tcol,$caja));
     }
     if(!empty($ctab))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Cta.Banc. :'));
          $col=$row->appendChild($domg->createElement($tcol,$ctab));
     }
     if(!empty($vhcl))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Vehículo :'));
          $col=$row->appendChild($domg->createElement($tcol,$vhcl));
     }
     if(!empty($pcnt))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Paciente :'));
          $col=$row->appendChild($domg->createElement($tcol,$pcnt));
     }
     if(!empty($cntn))
     {
          $row=$root->appendChild($domg->createElement($trow));     
          $col=$row->appendChild($domg->createElement('th','Contenedor :'));
          $col=$row->appendChild($domg->createElement($tcol,$cntn));
     }
     
     $row=$root->appendChild($domg->createElement($trow));
     
     $row=$root->appendChild($domg->createElement($trow));
          $row->setAttribute('style','background-color:#e0e0e0;');
     $col=$row->appendChild($domg->createElement('th',''));
     $col=$row->appendChild($domg->createElement('th',''));
     $col=$row->appendChild($domg->createElement('th','L'));
     for($xcol=0; $xcol<msql_num_fields($zreso); $xcol++)
     {
          if(substr(msql_field_name($zreso,$xcol),-5)!='_hide')
          {
               $value=msql_field_name($zreso,$xcol);
               $value=strtoupper($value);
               $col=$row->appendChild($domg->createElement('th',htmlspecialchars($value)));
          }
     }



     $crow =0;
     msql_data_seek($zreso,0);
     for($xrow=0; $xrow<msql_num_rows($zreso); $xrow++)
     {
          $row=$root->appendChild($domg->createElement($trow));
          $crow++;
          
          $style='vertical-align:top;';
          if($crow%2==0)
          {$style.='background-color:#f0f0f0;';}
          $row->setAttribute('style',$style);
          
          $col=$row->appendChild($domg->createElement($tcol,''));
          $col=$row->appendChild($domg->createElement($tcol,''));
          $col=$row->appendChild($domg->createElement($tcol,$crow));
          for($xcol=0; $xcol<msql_num_fields($zreso); $xcol++)
          {
               if(substr(msql_field_name($zreso,$xcol),-5)!='_hide')
               {
                    $value=msql_result($zreso,$xrow,msql_field_name($zreso,$xcol));
//                     if(mb_stristr('enti.item.ctas.ptoe',msql_field_name($zreso,$xcol))) 
//                     {$value=" ".$value;}
//                     if(mb_stristr('e_bode',msql_field_name($zreso,$xcol))) 
                    if(msql_field_name($zreso,$xcol)=='e_bode') 
                    {
                         foreach ($ebode as $key1=>$val1)
                         {
                              foreach($val1 as $key2=>$val2)
                              if($key2=='numfac' and $val2==msql_result($zreso,$xrow,'numero')){$value=$val1['ebode']; break 2;}
                         }
                         if($value<1/100000){$value=0;}
                    }
                    
                    if(mb_stristr('ttricc.',$info))
                    {
                         if(msql_field_type($zreso,$xcol)=='int' or msql_field_type($zreso,$xcol)=='real')
                         {$value=$value*(-1);}
                    }
                    
                    $col=$row->appendChild($domg->createElement($tcol,htmlspecialchars($value)));
                    if(mb_stristr('codigo.enti.item.ctas.ptoe',msql_field_name($zreso,$xcol))) 
                    {$col->setAttribute('class','text');}
               }
          }
     }     
     $html2=$domg->saveHTML();
     $file_content.=$html2;
     file_put_contents($file_php_xls,$file_content); 


?>