即使生成excel表格的问题 但问题是他总是打开一个下载框,现在名为consolo的文件(我的以上的代码就是封装在consolo.php)里的;我如果选则下载的话,就会下到一个叫consolo的文件,里面只有以上代码,没有我要的即时生成的$filename,请大虾们指点一下哦 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 需要输出每个单元格的数据的呀。header("Content-type:application/vnd.ms-excel");header("Content-Disposition:filename=test.xls");include_once "Connect.inc.php";$link = new Connect();$sql = "select * from ftp";$array = $link->Execute($sql);echo "公司名称\t用户名\t密码\t端口\t\n";foreach($array as $row){ echo $row["company"]."\t".$row["usename"]."\t".$row["password"]."\t".$row["port"]."\t\n";} 好象还是不行是否要将consolo.php 改成consolo.xls?? 无论如何不可能得到代码吧?除非你的php没有解析运行 echo ("aa");//显示为aa算不算被解析了呢??除非你的php没有解析运行,我觉得不是这个问题! aa不是代码啊从程序来看,fopen/fwrite数据到一个文件是不正确的应该使用程序中那两个header,然后直接向客户端echo就可以了 <?php/* * Created on 2006-6-29 * * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */ class DataSource{ private $action; private $game_kind; private $game_sequence; function DataSource($action,$game_kind,$game_sequence=null) { if($this->test_action_param($action)&&$this->test_game_kind_param($game_kind)){ $this->action=$action; $this->game_kind=$game_kind; } if($this->test_game_sequence_param($game_sequence)){ $this->game_sequence=$game_sequence; } } function fetch_table(){ global $gDB; if($this->action=='team_info_download'){ $query_str="SELECT * FROM actual_team_info WHERE game_kind={$this->game_kind}"; $gDB->query($query_str); //var_dump($query_str); if($gDB->query_is_success()){ $file_name="temp/$this->game_kind"."_".date('Ymd$Gis').".xls"; $fp = fopen($file_name, "w"); header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:filename=$file_name"); foreach($gDB->Record as $key => $value){ echo "$key\t";//用echo了!!!!!!! //var_dump($value); if(fwrite($fp,"$key\t")===false){ echo "写入错误:$formatted_path"; exit; } } do{ foreach($gDB->Record as $value){ echo "$value\t"; } }while($gDB->next_record()); } else{ echo('数据返回有误'); exit(); } fclose($fp); //echo($file_name); } else if($this->action=='team_info_upload'){ //$query_str="INSERT INTO member_match_info_hist(game_kind,match_seq_no,member_id,price,point,team_name,point_detail,buyer_count,status) VALUES('{$game_kind}',$match_seq_no,$member_id,$price,$point,'{$team_name}','$point_detail',$buyer_count,'{$status}')"; //$gDB->query($query_str); } } private function test_action_param($action){ if($action=='team_info_download'||$action=='team_info_upload'){ return true; } else{ echo('动作选项参数有误'); exit(); } } private function test_game_kind_param($game_kind){ if(in_array($game_kind,array(1,6,10,2,7,8,17,5,11))){ return true; } else{ echo('联赛类型选项参数有误'); exit(); } } private function test_game_sequence_param(){ return true; } } require('../mywan/phplib/db_oci8.inc'); $gDB = new DB_Sql(); $gDB->User = 'xxxxx'; $gDB->Password = 'xxxxx'; $gDB->Database = 'game50'; $action=$_POST['action']; //echo $action; $game_kind=$_POST['game_kind']; $game_sequence=$_POST['game_sequence']; $data_source=new DataSource($action,$game_kind,$sequence); $data_source->fetch_table();?>改了,还是老样子,那个写入(fwrite)应该没有关系吧.现在我用echo ! 具体到你的class思路我很难介入给个短程序你参考<?phpheader("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";?>另外,个人建议你加上去缓存的header因为我试过在一个旧程序(曾经运行过)加上上述代码,用f5刷新也是输出text字串,在地址栏按回车才能输出excel,不知道你是不是这个问题 when you end writing the xls file,redirect to the file like:<script>window.open("test.xls");</script> or use header("location:test.xls"); 楼上的大哥,我以上的代码只能生成一个consolo.xls的文件下载,要下载后双击打开;但不能自动打开. header("Content-type:application/vnd.ms-excel");header("Content-Disposition:filename=consolo.xls");header("location:consolo.xls");无法重定向! PHP的preg_replace 正则替换。怎么用 php如何控制将数据生成到已有的word报表中?有简单的实例最好 如何转换字符编码 smarty求助 谁帮忙写一下这个正则 简单问题,如何计算两个时间之间相差多少年? 一个高深的有意思的关于表单提交的问题 各位大虾,我准备做一个网上销售音像制品的电商网站,是用linux+php好还是windows+asp好? 谁知道哪里有免费空间吗? 超级自助建站系统下载! 求小偷程序 date时间函数的问题
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");include_once "Connect.inc.php";
$link = new Connect();
$sql = "select * from ftp";
$array = $link->Execute($sql);
echo "公司名称\t用户名\t密码\t端口\t\n";
foreach($array as $row)
{
echo $row["company"]."\t".$row["usename"]."\t".$row["password"]."\t".$row["port"]."\t\n";
}
从程序来看,fopen/fwrite数据到一个文件是不正确的
应该使用程序中那两个header,然后直接向客户端echo就可以了
/*
* Created on 2006-6-29
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
class DataSource{
private $action;
private $game_kind;
private $game_sequence;
function DataSource($action,$game_kind,$game_sequence=null) {
if($this->test_action_param($action)&&$this->test_game_kind_param($game_kind)){
$this->action=$action;
$this->game_kind=$game_kind;
}
if($this->test_game_sequence_param($game_sequence)){
$this->game_sequence=$game_sequence;
}
}
function fetch_table(){
global $gDB;
if($this->action=='team_info_download'){
$query_str="SELECT * FROM actual_team_info WHERE game_kind={$this->game_kind}";
$gDB->query($query_str);
//var_dump($query_str);
if($gDB->query_is_success()){
$file_name="temp/$this->game_kind"."_".date('Ymd$Gis').".xls";
$fp = fopen($file_name, "w");
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=$file_name");
foreach($gDB->Record as $key => $value){
echo "$key\t";//用echo了!!!!!!!
//var_dump($value);
if(fwrite($fp,"$key\t")===false){
echo "写入错误:$formatted_path";
exit;
}
}
do{
foreach($gDB->Record as $value){
echo "$value\t";
}
}while($gDB->next_record());
}
else{
echo('数据返回有误');
exit();
}
fclose($fp);
//echo($file_name);
}
else if($this->action=='team_info_upload'){
//$query_str="INSERT INTO member_match_info_hist(game_kind,match_seq_no,member_id,price,point,team_name,point_detail,buyer_count,status) VALUES('{$game_kind}',$match_seq_no,$member_id,$price,$point,'{$team_name}','$point_detail',$buyer_count,'{$status}')";
//$gDB->query($query_str);
}
}
private function test_action_param($action){
if($action=='team_info_download'||$action=='team_info_upload'){
return true;
}
else{
echo('动作选项参数有误');
exit();
}
}
private function test_game_kind_param($game_kind){
if(in_array($game_kind,array(1,6,10,2,7,8,17,5,11))){
return true;
}
else{
echo('联赛类型选项参数有误');
exit();
}
}
private function test_game_sequence_param(){
return true;
}
}
require('../mywan/phplib/db_oci8.inc');
$gDB = new DB_Sql();
$gDB->User = 'xxxxx';
$gDB->Password = 'xxxxx';
$gDB->Database = 'game50';
$action=$_POST['action'];
//echo $action;
$game_kind=$_POST['game_kind'];
$game_sequence=$_POST['game_sequence'];
$data_source=new DataSource($action,$game_kind,$sequence);
$data_source->fetch_table();
?>
改了,还是老样子,那个写入(fwrite)应该没有关系吧.
现在我用echo !
给个短程序你参考<?php
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";
?>另外,个人建议你加上去缓存的header
因为我试过在一个旧程序(曾经运行过)加上上述代码,用f5刷新也是输出text字串,在地址栏按回车才能输出excel,不知道你是不是这个问题
<script>
window.open("test.xls");
</script> or use header("location:test.xls");
header("Content-Disposition:filename=consolo.xls");
header("location:consolo.xls");无法重定向!