Ver Mensaje Individual
  #6 (permalink)  
Antiguo 09/09/2014, 01:55
Avatar de CHuLoSoY
CHuLoSoY
 
Fecha de Ingreso: febrero-2002
Ubicación: Ribeira (Galicia)
Mensajes: 1.900
Antigüedad: 22 años, 2 meses
Puntos: 29
Respuesta: Insertar Hoja De Calculos En Pagina Web

Lo bueno que tienen las hojas de cálculo es que las puedes hacer con un html sencillo de <tables> y el resultado lo pintas diciéndole al navegador las cabeceras adecuadas, indicando que es un fichero con el mimetype spreadsheet.
La otra ventaja es que existen librerías u objetos preparados para el tema.

Échale un vistazo a esto:
https://phpexcel.codeplex.com/
https://github.com/PHPOffice/PHPExcel

Por otro lado, un ejemplo de código que tengo hecho de hace varios años y sigue funcionando:

Código PHP:
Ver original
  1. header("Content-type: application/vnd.ms-excel; charset=iso-8859-1");
  2.             header("Expires: 0");
  3.             header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4.             header("Content-Disposition: attachment; filename=Informe_".date("Y-m-d",time()).".xls");
  5.             header("Content-Transfer-Encoding: binary");
  6.             $html = <<<EOH
  7.                                     <html xmlns:o="urn:schemas-microsoft-com:office:office"
  8.                     xmlns:x="urn:schemas-microsoft-com:office:excel"
  9.                     xmlns="http://www.w3.org/TR/REC-html40">
  10.  
  11.                     <head>
  12.                     <meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
  13.                     <meta name=ProgId content=Excel.Sheet>
  14.                     <!--[if gte mso 9]><xml>
  15.                      <o:DocumentProperties>
  16.                       <o:LastAuthor>Sriram</o:LastAuthor>
  17.                       <o:LastSaved>2005-01-02T07:46:23Z</o:LastSaved>
  18.                       <o:Version>10.2625</o:Version>
  19.                      </o:DocumentProperties>
  20.                      <o:OfficeDocumentSettings>
  21.                       <o:DownloadComponents/>
  22.                      </o:OfficeDocumentSettings>
  23.                     </xml><![endif]-->
  24.                     <style>
  25.                     <!--table
  26.                             {mso-displayed-decimal-separator:"\.";
  27.                             mso-displayed-thousand-separator:"\,";}
  28.                     @page
  29.                             {margin:1.0in .75in 1.0in .75in;
  30.                             mso-header-margin:.5in;
  31.                             mso-footer-margin:.5in;}
  32.                     tr
  33.                             {mso-height-source:auto;}
  34.                     col
  35.                             {mso-width-source:auto;}
  36.                     br
  37.                             {mso-data-placement:same-cell;}
  38.                     .style0
  39.                             {mso-number-format:General;
  40.                             text-align:general;
  41.                             vertical-align:bottom;
  42.                             white-space:nowrap;
  43.                             mso-rotate:0;
  44.                             mso-background-source:auto;
  45.                             mso-pattern:auto;
  46.                             color:windowtext;
  47.                             font-size:10.0pt;
  48.                             font-weight:400;
  49.                             font-style:normal;
  50.                             text-decoration:none;
  51.                             font-family:Arial;
  52.                             mso-generic-font-family:auto;
  53.                             mso-font-charset:0;
  54.                             border:none;
  55.                             mso-protection:locked visible;
  56.                             mso-style-name:Normal;
  57.                             mso-style-id:0;}
  58.                     td
  59.                             {mso-style-parent:style0;
  60.                             padding-top:1px;
  61.                             padding-right:1px;
  62.                             padding-left:1px;
  63.                             width:200px;
  64.                             mso-ignore:padding;
  65.                             color:windowtext;
  66.                             font-size:10.0pt;
  67.                             font-weight:400;
  68.                             font-style:normal;
  69.                             text-decoration:none;
  70.                             font-family:Arial;
  71.                             mso-generic-font-family:auto;
  72.                             mso-font-charset:0;
  73.                             mso-number-format:General;
  74.                             text-align:general;
  75.                             vertical-align:bottom;
  76.                             border:none;
  77.                             mso-background-source:auto;
  78.                             mso-pattern:auto;
  79.                             mso-protection:locked visible;
  80.                             white-space:nowrap;
  81.                             mso-rotate:0;}
  82.                     .xl24
  83.                             {mso-style-parent:style0;
  84.                             white-space:normal;}
  85.                          
  86.                     th
  87.                             {text-align:center;
  88.                             font-weight:bold;}
  89.                            
  90.                     -->
  91.                     </style>
  92.                     <!--[if gte mso 9]><xml>
  93.                      <x:ExcelWorkbook>
  94.                       <x:ExcelWorksheets>
  95.                        <x:ExcelWorksheet>
  96.                             <x:Name>srirmam</x:Name>
  97.                             <x:WorksheetOptions>
  98.                              <x:Selected/>
  99.                              <x:ProtectContents>False</x:ProtectContents>
  100.                              <x:ProtectObjects>False</x:ProtectObjects>
  101.                              <x:ProtectScenarios>False</x:ProtectScenarios>
  102.                             </x:WorksheetOptions>
  103.                        </x:ExcelWorksheet>
  104.                       </x:ExcelWorksheets>
  105.                       <x:WindowHeight>20005</x:WindowHeight>
  106.                       <x:WindowWidth>20005</x:WindowWidth>
  107.                       <x:WindowTopX>120</x:WindowTopX>
  108.                       <x:WindowTopY>135</x:WindowTopY>
  109.                       <x:ProtectStructure>False</x:ProtectStructure>
  110.                       <x:ProtectWindows>False</x:ProtectWindows>
  111.                      </x:ExcelWorkbook>
  112.                     </xml><![endif]-->
  113.                     </head>
  114.  
  115.                     <body link=blue vlink=purple>
  116.                     <table x:str border=0 cellpadding=0 cellspacing=0 style='border-collapse: collapse;table-layout:fixed; font-family: Arial'>
  117. EOH;
  118.            
  119.             switch($this->Action) {
  120.                                
  121.                 case "getReportByUser":
  122.                     //Informe individual por usuario
  123.                     $html.= $this->getReportByUser($idUser, 1);
  124.                     break;
  125.                
  126.                 default :
  127.                     //Error si no se encuentra la acción
  128.                     $html.=$this->Error();
  129.                     break;
  130.                
  131.             }
  132.            
  133.            
  134.             $html.="</table></body></html>";
  135.            
  136.            
  137.             return $html;
  138.            
  139.         }
  140.         private function getReportByUser($user, $type) {
  141.                  return "<tr><td>Col 1 Row 1</td><td>Col 2 Row 1</td></tr><tr><td>Col 1 Row 2</td><td>Col 2 Row 2</td></tr>";
  142.         }

Espero te sea útil la información.

Saludos.
__________________
ESQUIO Dominios y Hosting
Las mejores características con los mejores precios.