Excel 2007 official Download free full version PHP method for exporting a database to Excel

Source: Internet
Author: User
Upload CVS and import into the database, the test is successful (some of the code is not standardized, such as php_self there to rewrite into $_server["php_self"])
PHP code

Copy the Code code as follows:


$fname = $_files[' MyFile ' [' name '];
$do = Copy ($_files[' MyFile ' [' tmp_name '], $fname);
if ($do)
{
echo "Import data successfully
";
} else {
echo "";
}
?>

error_reporting (0);
Import files in CSV format
$c or Die ("could not connect to database");
mysql_select_db ("a0530093319", $connect) or Die (Mysql_error ());
$fname = $_files[' MyFile ' [' name '];
$handle =fopen ("$fname", "R");
while ($data =fgetcsv ($handle, 10000, ","))
{
$q = "INSERT INTO Test (code,name,date) VALUES (' $data [0] ', ' $data [1] ', ' $data [2] ')";
mysql_query ($q) or Die (Mysql_error ());
}
Fclose ($handle);
?>
Use PHP to export the database to Excel, test completely successful
PHP Code www.devdao.com
$DB _server = "localhost";
$DB _username = "root";
$DB _password = "";
$DB _dbname = "Ishop";
$DB _tblname = "Oi_mall_payment";
$savename = Date ("Ymjhis");
$Connect = @mysql_connect ($DB _server, $DB _username, $DB _password) or Die ("couldn ' t Connect.");
mysql_query ("Set Names ' GBK '");
$file _type = "Vnd.ms-excel";
$file _ending = "xls";
Header ("content-type:application/$file _type;charset=big5");
Header ("content-disposition:attachment; Filename= ". $savename.". $file _ending ");
Header ("Pragma:no-cache");
$now _date = Date ("Y-m-j h:i:s");
$title = "Database name: $DB _dbname, Data sheet: $DB _tblname, Backup date: $now _date";
$sql = "SELECT * from $DB _tblname";
$ALT _db = @mysql_select_db ($DB _dbname, $Connect) or Die ("couldn ' t Select Database");
$result = @mysql_query ($sql, $Connect) or Die (Mysql_error ());
Echo ("$title \ n");
$sep = "\ t";
for ($i = 0; $i < Mysql_num_fields ($result); $i + +) {
Echo Mysql_field_name ($result, $i). "\ t";
}
Print ("\ n");
$i = 0;
while ($row = Mysql_fetch_row ($result)) {
$schema _insert = "";
for ($j =0; $j
if (!isset ($row [$j]))
$schema _insert. = "NULL". $sep;
ElseIf ($row [$j]! = "")
$schema _insert. = "$row [$j]". $sep;
Else
$schema _insert. = "". $sep;
}
$schema _insert = Str_replace ($sep. " $ "," ", $schema _insert);
$schema _insert. = "\ T";
Print (Trim ($schema _insert));
print "\ n";
$i + +;
}
return (true);
?>

The above describes the official Excel 2007 download free full version of PHP to export the database into Excel, including the official download of the Excel 2007 free full version of the content, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.