PHP generates Excel file implementation code

Source: Internet
Author: User

<p> There is a period of time did not update the blog, for fear of being Baidu forgotten Ah, biu~biu~. Recently there is a project to count the URL and title of the site, save in Excel, the following is the specific code </p>

<pre class= "php" name= "code" ><!--p

PHP generates Excel reports by sending header () header information
Header ("Content-type:application/vnd.ms-execl");
Header ("Content-type:application/vnd.ms-excel; charset=gb2312 ");
Tell the browser the name of the file and ask the client to download
Header ("Content-disposition:filename=test.xls");
Header ("Pragma:no-cache");
Header ("expires:0");

$link = mysql_connect (' localhost ', ' root ', ') or die (' could not connect: '. Mysql_error ());
mysql_select_db (' Novartis ') or die (' could not select database ');

mysql_query ("SET NAMES gb2312");
$query = ' SELECT title,keywords,url,description from Cms_content ';
$result = mysql_query ($query) or Die (' Query failed: '. mysql_error ());
Display results in HTML
$str =mb_convert_encoding ("Test 1", "gb2312", "utf-8");
echo "Titlet";
echo "KEYWORDST";
echo "Descriptiont";
echo "Urltn";
/* Format: NewLine: "tn": Between Cells: "T" * *

while ($line = Mysql_fetch_array ($result, Mysql_assoc)) {
echo $line [' title ']. T ";
echo $line [' keywords ']. T ";
echo $line [' description ']. T ";
echo $line [' url ']. TN ";

}


Releasing the result set
Mysql_free_result ($result);
Close connection
Mysql_close ($link);
-->
</pre>
<div>&nbsp;</div>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.