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>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.