Search code examples
phpspreadsheet-excel-writer

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?

Thx a lot.


Solution

  • 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()).

    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.