Check out the DocRaptor if you need formatting to be exact. This is a SaaS built around the prince of XML.
https://docraptor.com/
Here is an example of using PHP (output to Excel spreadsheet instead of PDF)
https://docraptor.com/documentation#php_example
<?php $api_key = "YOUR_API_KEY_HERE"; $url = "https://docraptor.com/docs?user_credentials=$api_key"; $document_content = "<table><tr><td>Cell</td></tr></table>"; $request = new HTTPRequest($url, HTTP_METH_POST); $request->setPostFields(array('doc[document_content]' => $document_content, 'doc[document_type]' => 'xls', 'doc[name]' => 'my_doc.xls', 'doc[test]' => 'true')); $request->send(); $file = fopen ("my_excel_doc.xls", "w"); fwrite($file, $request->getResponseBody()); fclose ($file); ?>
source share