Spreadsheet_Excel_Writer get file content


Spreadsheet_Excel_Writer get file content



I need to attach an XLS-file to e-mail via PHP.
The Problem is - Spreadsheet_Excel_Writer send a HTTP Header to a browser an then the content. Spreadsheet_Excel_Writer API has no any functions like get_content to become the file content directly. I don't want to save the file first, I just want to jump this step over, saving the content directly as attachment.
Any ideas?


Spreadsheet_Excel_Writer


Spreadsheet_Excel_Writer


get_content



Thx a lot.




3 Answers
3



There isn't a "write to file" method in Spreadsheet_Excel_Writer. At most you can send it directly to the client with the ->send() method. This means you COULD capture the output with PHP's output buffering, and grab the data as a string, which can then be inserted into an email (e.g. via PHPMailer's ->AddStringAttachment()).


->send()


->AddStringAttachment()



You may want to investigate switching to PHPExcel, since Spreadsheet_Excel_Writer is essentially dead in the water, minus a few minor bug fixes. PHPExcel supports Excel 2007, while S_E_W is stuck at Excel 5.0 (early 90's). It also has a ->save() method to write to file.


->save()





the file i generate with PEAR-Spreadsheet_Excel_Writer-0.9.3...is in Read-Only Mode, Any idea to solve it ?
– Hytool
Sep 1 '16 at 9:32



Albeit the OP doesn't want to save the file first, I was looking for a means to output inline as opposed to attachment using the ::send method.


::send



The PEAR Spreadsheet_Excel_Writer 0.1 to 0.9.4 constructor supports a $filename argument. [sic 0.1]
and [sic 0.9.4]


Spreadsheet_Excel_Writer


0.1


0.9.4


$filename



When supplied, calling the Spreadsheet_Excel_Writer::close method on the instantiated object, will output the generated spreadsheet to the specified path.


Spreadsheet_Excel_Writer::close


$workbook = new Spreadsheet_Excel_Writer('/path/to/output/file.xls');
//...
$workbook->close();

$data = file_get_contents('/path/to/output/file.xls');
//or file_get_contents($workbook->_filename);
unlink('/path/to/output/file.xls');






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV