1

I have used the code below to generate a report in excel:

require_once "phpexcel/class.writeexcel_workbook.inc.php";
require_once "phpexcel/class.writeexcel_worksheet.inc.php";
$fname = tempnam("/tmp", "simple.xls");
$workbook = &new writeexcel_workbook($fname);
$gen =& $workbook->addformat();
$gen->set_align('left');
$gen->set_num_format('General');
$worksheet = &$workbook->addworksheet("records");
$worksheet->write_string(0,0,'Customer');
$worksheet->write_string(0,1,'ID');
$worksheet->set_column(0,0,30,$gen);
$worksheet->set_column(0,1,10,$gen);
$j=1;
while($res = mysql_fetch_array($qry))
{
    $worksheet->write($j,0,$res['cust']);
    $worksheet->write($j,1,$res['id']);
    $j++;
}
$workbook->close();
header("Content-Type: application/x-msexcel; name=records.xls");
header("Content-Disposition: inline; filename=records.xls");

When I run this file its generating output correctly but only the problem is if my records comes above 24000 then it shows an error message.

if I set 1 to 24000 records its working

if I set above 24000 records its working

if I set all then its not working (at the time 26000 records will come)

Noam Hacker
  • 4,671
  • 7
  • 34
  • 55
Joker
  • 23
  • 1
  • 7
  • might wanne try xlsx? – Naruto Apr 28 '16 at 12:31
  • "then it show error message" - let me guess - a memory error? Have you tried upping available to PHP? – h2ooooooo Apr 28 '16 at 12:32
  • Have you tried increasing your RAM capacity? – Justinas Apr 28 '16 at 12:36
  • Your'e not using PHPExcel; looks a bit like the PEAR Spreadsheet Excel Writer library; and the limit isn't a row limit, but is likely to be a memory limit on your server – Mark Baker Apr 28 '16 at 12:38
  • in my code i used ini_set('memory_limit', '128M'); and ini_set('memory_limit', '-1'); but no use – Joker Apr 28 '16 at 13:43
  • You can't be certain that `ini_set` will necessarily work. You might have to change it in your actual php.ini file. This is of course expecting that you're not running shared hosting (they might also have a max if you do). – h2ooooooo Apr 28 '16 at 14:21

1 Answers1

0

You may try this official example: https://github.com/PHPOffice/PHPExcel/blob/7d1c140974a4988f8a9739d167335d24fb59955e/Examples/06largescale-xls.php

Also, consider to increase PHP memory limit

PHPExcel holds an "in memory" representation of a spreadsheet, so it is susceptible to PHP's memory limitations. The memory made available to PHP can be increased by editing the value of the memory_limit directive in your php.ini file, or by using ini_set('memory_limit', '128M') within your code (ISP permitting).

Here is a similar question

Community
  • 1
  • 1
Jeremy Jumeau
  • 199
  • 2
  • 4
  • i have tried by using ini_set('memory_limit', '128M'); and ini_set('memory_limit', '-1'); but no use – Joker Apr 28 '16 at 13:44