Use php to generate an excel file? Header (Content-type: applicationvnd. ms-excel); header (Content-Disposition: Bytes); echotest1t; echotest2tn; echotest1t; echotest2tn; echotest1t; echotest2tn; echotest1t; echotest2tn; echotest1t Excel
Use php to generate an excel file
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 ";
?>
When you run the above code in the php environment, you can see the browser asking you whether to download the excel document, click save, and an excel file is added to the hard disk, you can see the final result when using excel.
In fact, when doing real applications, you can extract the data from the database, and then add \ t after each column of data ends, after each row ends, add the \ n method to echo it, and use header ("Content-type: application/vnd. ms-excel ") indicates that the excel file is output, and the file name output is text.xls using header (" Content-Disposition: filename=test.xls. In this case, OK.
We can modify the header so that it can output more files in different formats. This makes php easier to process various types of files.