Error bij export excel bestand

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Mark Eilander

Mark Eilander

10/04/2008 15:10:00
Quote Anchor link
Als ik een export doe van een sql query naar excel kirjg ik de foutmelding

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 27262959 bytes) in excel\test_excel.php on line 27

Memory size staat ingesteld op standaart

Maar neem aan dat dat geen problemen kan geven aangezien een excel bestand niet zo groot wordt, of heb ik dat verkeerd?

Het script:

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php

/**
 * @author Mark Eilander
 * @copyright 2008
 */


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();
   }

    function
GetTitels()
    {

        $m_oConnection = mysql_connect("localhost", "admin", "eenmaal") or die(mysql_error());
        mysql_select_db('excel', $m_oConnection) or die(mysql_error());

        $m_sQuery = "SELECT * FROM survey_5171";

        $m_aResult = mysql_query($m_sQuery);
        $m_nCount = mysql_num_fields($m_aResult);

        for ($m_nCounter = 0; $m_nCounter < $m_nCount; $m_nCounter++) {

            $m_nVeldNaam = mysql_field_name($m_aResult, $m_nCounter);
            $m_nVeldNaam = str_replace("Vr_", "", $m_nVeldNaam);
            $m_nVeldNummer = explode("_", $m_nVeldNaam);

            if ($m_nVeldNummer[1] != "") {

                $m_sQueryVeldNaam = "SELECT Titel FROM Vragen WHERE VID = ".$m_nVeldNummer[0]."";

                $m_aResultVeldNaam = mysql_query($m_sQueryVeldNaam);
                $m_sRowVeldNaam = mysql_fetch_row($m_aResultVeldNaam);

                // Code uit script van maurice, geen idee wat dit doet.
                //$Titel_clean = str_replace(" ", "_", $m_sRow[0]);
                //$Titel_clean = str_replace("(", "", $Titel_clean);
                //$Titel_clean = str_replace(")", "", $Titel_clean);

                //echo $m_sRowVeldNaam[0]."_".$m_nVeldNummer[1]."<br />";

                $m_aArray[] = $m_sRowVeldNaam[0] . "_" . $m_nVeldNummer[1];
            }
else {
                //echo $m_nVeldNummer[0]."<br />";
                $m_aArray[] = $m_nVeldNummer[0];
            }
        }

        return $m_aArray;
    }
    
    function
GetContent()
    {
    
        $m_oConnectionContent = mysql_connect("localhost", "admin", "eenmaal") or die(mysql_error());
        mysql_select_db('excel', $m_oConnectionContent) or die(mysql_error());

        $m_sQueryContent = "SELECT * FROM survey_5171";

        $m_aResultContent = mysql_query($m_sQueryContent);
        $m_nCountContent = mysql_num_rows($m_aResultContent);
        
        while ($m_sRowContent = mysql_fetch_assoc($m_aResultContent)) {
            foreach ($m_sRowContent as $key => $value)
            {

                $m_aContent[] = $value;
            }

        $this->addRow($m_aContent);
        }
    }
}

 
$xls = new ExcelExport();
 
$m_aTitels = $xls->GetTitels();
$xls->addRow($m_aTitels);
$xls->GetContent();
$xls->download("websites.xls");


/*
* tel het aantal rijen in de array
*echo count($m_aArray);
*/


?>
 
PHP hulp

PHP hulp

16/01/2022 11:45:38
 
Jesper Diovo

Jesper Diovo

10/04/2008 15:41:00
Quote Anchor link
Op line 27 geeft 'ie aan dat daar het bestand al te groot is. Dus denk 't wel ;-).
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.