mysql exporteren naar excel

Status
Niet open voor verdere reacties.

comass

Gebruiker
Lid geworden
19 dec 2000
Berichten
448
Hoi,

Iemand een idee of een link hoe ik php pagina met tabellen kan exporteren naar Excel.
Niet vanaf PHP admin maar van uit de bestaande pagina.
 
cut & paste

op de (live) pagina gaan staan; aanslepen; ctrl+c;
ctrl+v in excel
dit is dus de scherm informatie
vanaf het back-end idem
 
Zo werkt het bij mij

Hoi,

Zo heb ik het gemaakt en werkt het.
Bestandsnaam: ExcelExport.php

PHP:
<?php
class ExcelExport {
   var $file;
   var $row;

   function ExcelExport() {
      $this->file = $this->__BOF();
      $row = 0;
   }

   function __BOF() {
       return pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
   }

   function __EOF() {
       return pack("ss", 0x0A, 0x00);
   }

   function __writeNum($row, $col, $value) {
       $this->file .= pack("sssss", 0x203, 14, $row, $col, 0x0);
       $this->file .= pack("d", $value);
   }

   function __writeString($row, $col, $value ) {
       $L = strlen($value);
       $this->file .= pack("ssssss", 0x204, 8 + $L, $row, $col, 0x0, $L);
       $this->file .= $value;
   }
   
   function writeCell($value,$row,$col) {
      if(is_numeric($value)) {
         $this->__writeNum($row,$col,$value);
      }elseif(is_string($value)) {
         $this->__writeString($row,$col,$value);
      }
   }
   
   function addRow($data,$row=null) {
      //If the user doesn't specify a row, use the internal counter.
      if(!isset($row)) {
         $row = $this->row;
         $this->row++;
      }
      for($i = 0; $i<count($data); $i++) {
         $cell = $data[$i];
         $this->writeCell($cell,$row,$i);
      }
   }

   function download($filename) {
      header("Pragma: public");
      header("Expires: 0");
      header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      header("Content-Type: application/force-download");
      header("Content-Type: application/octet-stream");
      header("Content-Type: application/download");;
      header("Content-Disposition: attachment;filename=$filename ");
      header("Content-Transfer-Encoding: binary ");
      $this->write();
   }
   
   function write() {
      echo $file = $this->file.$this->__EOF();
   }
}
?>

Bestandsnaam: download.php
PHP:
<?

require_once ("ExcelExport.php");
include_once ("verbinding.php");

$xls = new ExcelExport();
 
 
$xls->addRow(Array("ID","Soort","Naam","Adres","Postcode","Woonplaats","Telefoon","Email","Opmerking"));

$query = mysql_query("SELECT * FROM Jouw tabel");
$resultaat = mysql_query($query); 
while ($list = mysql_fetch_object($query)) { 

$xls->addRow(Array("$list->id","$list->subject",$list->aanhef $list->voorletter $list->achternaam","$list->adres","$list->postcode","$list->woonplaats","$list->telefoon","$list->email","$list->opmerking"));


}
$xls->download("websites.xls");
?>
 
Je bent een dubbele quote vergeten of je hebt er één te veel, ik denk dat het dat laatste is.

PHP:
$xls->addRow(Array("$list->id","$list->subject",$list->aanhef $list->voorletter $list->achternaam","$list->adres","$list->postcode","$list->woonplaats","$list->telefoon","$list->email","$list->opmerking));
 
Tabellen sorteren

Hoi,

Verkeerd geplakt waarschijnlijk bij werkt het.
 
Excel export als dump op scherm ipv bestand downloaden

Hoi,

Ik heb bovenstaande code gebruikt om data vanuit een MySQL database naar Excel te exporteren, maar ipv een bestand dat wordt gedownload krijg ik steeds een dump van de data op het scherm.
Weet iemand hoe ik dat kan oplossen?

Alvast bedankt.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan