Excel| Build Excel
PHP to generate Excel documents is too simple, it is estimated that everyone will use, so share out.
Let's look at the code:
?
Header ("Content-type:application/vnd.ms-excel");
Header ("Content-disposition:filename=test.xls");
echo "Test1\t";
echo "test2\t\n";
echo "Test1\t";
echo "test2\t\n";
echo "Test1\t";
echo "test2\t\n";
echo "Test1\t";
echo "test2\t\n";
echo "Test1\t";
echo "test2\t\n";
echo "Test1\t";
echo "test2\t\n";
?>
In the PHP environment to run the above code, you can see the browser to ask the user whether to download the Excel document, click Save, the hard drive on the more than an Excel file, use Excel to open will see the final results, how good it.
In fact, when doing real application, you can take the data out of the database, and then after each column of data plus \ t, after each row of data added \ n method echo out, in the beginning of PHP with header ("content-type:application/ Vnd.ms-excel "); indicates that the output is an Excel file, with the header (" Content-disposition:filename=test.xls "); The file name for the output is Text.xls. That's OK.
We can also modify the header to let him output more format files so that PHP is more convenient for processing various types of files