Php parse excel with multiple sheets

I currently have an excel (.htm) file that I use as a template for my invoices. After the user selects an invoice and click the submit button, the template is processed with invoice information and the prompt allows the user to save the file to their computer as an excel file (.xls).

Now I need to allow the user to select multiple invoices. Each selected invoice must be analyzed on a different sheet.

What I have done so far: I edited the template and created sheet2 from the data copied to sheet1, but I am getting an error.

Is there a way to choose which worksheet I need for my analysis? Any advice on perhaps an easier way to do this?

This prepares my output file

//Prepare the output file
header("Content-type: application/");
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");



source to share

1 answer

You cannot automatically rotate HTML markup into an Excel file by simply sending the appropriate headers to the browser. What you are doing is still sending the HTML file to the user and MS Excel will forgive and open it (but this is MS Excel that parses / converts the html markup into a format it can understand and display), not the headers that you submitting ... please note that most recent versions of MS Excel may throw a warning message when doing this, not the largest UI.

When MS Excel parses / converts HTML file, it only processes markup on one sheet only; so unless you change the way you work with the real Excel file, you won't be able to create a file that will count as two or more worksheets in MS Excel.

The list of answers to this question can be found in the list of libraries that can create "real" Excel files. My own preferred choice is to use PHPExcel (I'm biased, I'm a lead developer). However, you will need to rewrite the template as an Excel template, not HTML ... the roadmap for next year includes the ability to parse HTML into Excel, which would allow multiple sheets to be generated from multiple "pages" html, but this option not yet available (probably not until June).



All Articles