Generate excel files using php
<?
header("Content-type:application/-excel");
header("Content-Disposition:filename=");
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";
?>
Run the above code in the php environment, and you can see that the browser asks the user whether to download the Excel document. Click Save, and there will be an additional Excel file on the hard disk. Open it with Excel and you will see the final result. How is it good?
In fact, when doing real applications, you can take the data out of the database, and then add \t after each column of data, and add \n after each row of data. At the beginning of php, use header("Content-type:application/-excel"); to indicate that the output is an excel file, and use header("Content-Disposition:filename="); to indicate that the output file name is. This will be OK.
We can also modify the header to output more format files, so that php will be more convenient for processing various types of files.
<?
header("Content-type:application/-excel");
header("Content-Disposition:filename=");
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";
?>
Run the above code in the php environment, and you can see that the browser asks the user whether to download the Excel document. Click Save, and there will be an additional Excel file on the hard disk. Open it with Excel and you will see the final result. How is it good?
In fact, when doing real applications, you can take the data out of the database, and then add \t after each column of data, and add \n after each row of data. At the beginning of php, use header("Content-type:application/-excel"); to indicate that the output is an excel file, and use header("Content-Disposition:filename="); to indicate that the output file name is. This will be OK.
We can also modify the header to output more format files, so that php will be more convenient for processing various types of files.