Re: Structures_DataGrid_Renderer_XLS: I just get empty files
| From: | Markus Ernst | Date: | Tue, 27 Feb 2007 16:10:40 +0000 |
| Subject: | Re: Structures_DataGrid_Renderer_XLS: I just get empty files | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-26683@lists.php.net to get a copy of this message | ||
(Michael Mauch) schrieb:
Markus Ernst wrote:Thank you for your input! I updated all kinds of PEAR packages that could have any impact, with no success. Anyway as you wrote it worked for you, I tried to understand what happens in those Excel and OLE classes and finally found the reason: A Safe Mode restriction prevented the OLE File class from creating a temporary file! So here's the Safe Mode proof version of my code (csv part removed): <?php // Initiate and fill datagrid require_once 'Structures/DataGrid.php'; $datagrid =& new Structures_DataGrid(); $data = array( array(2 => 'Speàrs', 3 => 'Britñey'), array(2 => 'Wilłiams', 3 => 'Robbie'), array(2 => 'Jagger', 3 => 'Mick') ); $datagrid->bind($data); // Set columns $datagrid->addColumn(new Structures_DataGrid_Column('First Name', 3)); $datagrid->addColumn(new Structures_DataGrid_Column('Last Name', 2)); // Attach XLS renderer $filename = 'userlist_'.date('Y-m-d_H-i'); $options = array( 'filename' => $filename.'.xls' ); $options['encoding'] = 'utf-8'; $renderer =& $datagrid->setRenderer(DATAGRID_RENDER_XLS, $options); // Now we have to get the workbook object and set the temp directory // Of course this directory must be created manually and chmoded // with writing permission for PHP $workbook =& $renderer->getContainer(); $workbook->setTempDir($_SERVER['DOCUMENT_ROOT'].'/temp/'); // Output file $datagrid->render($renderer, $options); exit; ?>I use Structures_DataGrid for exporting database records to Excel. Anyway, all I get is an empty file which neither Excel nor OpenOffice can read, while the same works without problems with the CSV renderer. Here is my code with some test data:Your code nearly works for me, if I remove the linebreak here:header('Content-Disposition: attachment; filename="'.$filename.'.'.$suffix.'"');Maybe that was only a screwup of your newsreader. Open Office happily opens the resulting file. So probably the culprit is not your code. Perhaps you one of your PEAR packages is too old? Here I have:Structures_DataGrid 0.8.1 beta Structures_DataGrid_DataSource_Array 0.1.2 beta Structures_DataGrid_Renderer_XLS 0.1.1 beta