怀疑PHP到MS-Excel [英] Doubt on php to ms-excel
本文介绍了怀疑PHP到MS-Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
圣诞快乐,
我正在尝试在excel表中打印Mysql表.但是错误显示文件格式不同,我的excel文件格式是xlsx.这是我正在使用的代码.
Hi,
Merry X-mas,
I am trying to print the Mysql table in an excel sheet.But the Error shows that the file format is different,My excel file format is xlsx.Here is the code i am using.
<pre><?PHP // Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
function cleanData(&$str)
{
$str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
}
include("config.php");
$filename = "website_data_" . date('Ymd') . ".xlsx";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel"); $flag = false; $result = pg_query("SELECT * FROM jobrequirements") or die('Query failed!');
while(false !== ($row = pg_fetch_assoc($result)))
{
if(!$flag)
{
// display field/column names as first row
echo implode("\t", array_keys($row)) . "\r\n"; $flag = true; } array_walk($row, 'cleanData'); echo implode("\t", array_values($row)) . "\r\n"; } ?>
我无法解决.我请您帮助我解决此问题.
I couldn''t fix it.I request you to help me to fix this problem.
推荐答案
str) {
str) {
str = preg_replace(" ," ,
str);
str);
这篇关于怀疑PHP到MS-Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文