请教下导出到excel的问题 我是循环出的一个表格,想导出为一张excel表格,我网上找过,有phpexcel但是发现搞不定,有没有人能指点指点的,能附上代码更好,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.php100.com/html/webkaifa/PHP/PHPyingyong/2009/0114/309.html 在php开始加<?phpheader("Content-Type: application/vnd.ms-excel");header("Content-Disposition: attachment; filename=test.xls;");//导出的文件名?> 续自己在2L的回复<?php $con = mysql_connect("localhost","root","mysql") or die("无法连接到数据库".mysql_error()); mysql_select_db('berecord'); mysql_query('set names utf8');$where = ' '.'1=1';if ($_POST['name'] != ''){$where.=" and name = '".$_POST['name']."'";}if($_POST['carnumber']!=''){$where.=" and carnumber = '".$_POST['carnumber']."'";}if($_POST['do']!=''){$where.=" and zhixing='".$_POST['do']."'";}if($_POST['usercode']!=''){$where.="and usercode='".$_POST['usercode']."'";}$sql="select * from record where".$where.' '."and searchtime between '$date1' and '$date2'";然后再用$row['']; 输出就可以了 不知道符不符合楼主要求 http://blog.csdn.net/diyle/article/details/6340187 导出EXCEL用不着什么类,就3楼的就行。我给你一个完整的<?php/* * 文件创建时间 2010-8-26 * * 创建人:森林 * 联系方式:QQ 83202700 Email:[email protected] */ if(!$_COOKIE[username]) exit("请登陆后导出数据"); header("Content-type:appliction/vnd.ms-excel"); header("content-disposition:filename=CW-YCL".date("Ymdhis").".xls");include("data/conn.php");?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><META http-equiv=Content-Type content="text/html; charset=gb2312"><body> <TABLE cellSpacing=0 cellPadding=0 width="1000px" border=1><tr><td colspan=8><font size=5><b><center>EXCEL导出</center></b></font></td> </tr><tr><td colspan=8><center>半成品入库记录</center></td> </tr><tr><td colspan=8>制表日期:<?php echo date("Y-m-d")?></td></tr><tr><td>工令号</td><td>单据编号</td><td>料号</td><td>品名</td><td>数量</td><td>类型</td><td>日期</td><td>仓管操作员</td></tr></tr><?php$sqllld=mysql_query("SELECT * FROM `tyt_ckbcp_1` where dt>='$_POST[dtks]' && dt<='$_POST[dtjs]' order by id");while($rowslld=mysql_fetch_array($sqllld)){ ?><tr><td style="vnd.ms-excel.numberformat:@"><?php echo $rowslld[gldh]?></td><td><?php echo $rowslld[bianhao]?></td><td><?php echo $rowslld[liaohao]?></td><td><?php echo $rowslld[pingm]?></td><td><?php echo $rowslld[sl]?></td><td><?php echo $rowslld[bz]?></td><td><?php echo $rowslld[dt]?></td><td><?php echo $rowslld[username]?></td></tr><?php}?></table>本报表最终由:<?php echo $_COOKIE[username]?> 导出</body></head></html> 我是这么写的,但是导出的时候是乱码,请各位帮我看下。一个页面循环出表格,点击导出excel,跳转到新的页面,下面是这个页面的代码<?php$sql = "select * from shop ";$query = mysql_query($sql);while($row = mysql_fetch_array($query)){ $rows[] = $row;} header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=test.xlsx"); include 'PHPExcel.php'; //对文件的原子性操作类 include 'PHPExcel/IOFactory.php'; //顾名思义 以工厂模式封装的读写类 哈~ $PHPExcelObj = new PHPExcel(); $PHPExcelObj->setActiveSheetIndex(0); //在excel的第一张(Sheet1)表单上写入数据 $PHPExcelObj->getActiveSheet()->setCellValue('A1', '商品名称'); //A1是excel的 第1列第1行 $PHPExcelObj->getActiveSheet()->setCellValue('B1', '商品型号'); $PHPExcelObj->getActiveSheet()->setCellValue('C1', '商品数量'); $PHPExcelObj->getActiveSheet()->setCellValue('D1', '商品单价'); $PHPExcelObj->getActiveSheet()->setCellValue('E1', '商品用于'); $PHPExcelObj->getActiveSheet()->setCellValue('F1', '商品申请人'); $PHPExcelObj->getActiveSheet()->setCellValue('G1', '审批状态'); foreach($rows as $key=>$row){ $row_index = $key+2; $PHPExcelObj->getActiveSheet()->setCellValue('A'.$row_index, $row['shop_name']); //A1是excel的 第1列第1行 $PHPExcelObj->getActiveSheet()->setCellValue('B'.$row_index, $row['shop_type']); $PHPExcelObj->getActiveSheet()->setCellValue('C'.$row_index, $row['shop_shuliang']); $PHPExcelObj->getActiveSheet()->setCellValue('D'.$row_index, $row['shop_value']); $PHPExcelObj->getActiveSheet()->setCellValue('E'.$row_index, $row['shop_where']); $PHPExcelObj->getActiveSheet()->setCellValue('F'.$row_index, $row['shop_shenqing']); $PHPExcelObj->getActiveSheet()->setCellValue('G'.$row_index, $row['shop_state']); } $excelWriter = PHPExcel_IOFactory::createWriter($PHPExcelObj, 'Excel5'); $excelWriter->save('php://output'); exit();?> 一个页面循环出表格,点击导出按键,跳转新的页面,弹出保存excel对话框下面是这一页的内容<?php$sql = "select * from shop ";$query = mysql_query($sql);while($row = mysql_fetch_array($query)){ $rows[] = $row;} header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename=test.xlsx"); include 'PHPExcel.php'; //对文件的原子性操作类 include 'PHPExcel/IOFactory.php'; //顾名思义 以工厂模式封装的读写类 哈~ $PHPExcelObj = new PHPExcel(); $PHPExcelObj->setActiveSheetIndex(0); //在excel的第一张(Sheet1)表单上写入数据 $PHPExcelObj->getActiveSheet()->setCellValue('A1', '商品名称'); //A1是excel的 第1列第1行 $PHPExcelObj->getActiveSheet()->setCellValue('B1', '商品型号'); $PHPExcelObj->getActiveSheet()->setCellValue('C1', '商品数量'); $PHPExcelObj->getActiveSheet()->setCellValue('D1', '商品单价'); $PHPExcelObj->getActiveSheet()->setCellValue('E1', '商品用于'); $PHPExcelObj->getActiveSheet()->setCellValue('F1', '商品申请人'); $PHPExcelObj->getActiveSheet()->setCellValue('G1', '审批状态'); foreach($rows as $key=>$row){ $row_index = $key+2; $PHPExcelObj->getActiveSheet()->setCellValue('A'.$row_index, $row['shop_name']); //A1是excel的 第1列第1行 $PHPExcelObj->getActiveSheet()->setCellValue('B'.$row_index, $row['shop_type']); $PHPExcelObj->getActiveSheet()->setCellValue('C'.$row_index, $row['shop_shuliang']); $PHPExcelObj->getActiveSheet()->setCellValue('D'.$row_index, $row['shop_value']); $PHPExcelObj->getActiveSheet()->setCellValue('E'.$row_index, $row['shop_where']); $PHPExcelObj->getActiveSheet()->setCellValue('F'.$row_index, $row['shop_shenqing']); $PHPExcelObj->getActiveSheet()->setCellValue('G'.$row_index, $row['shop_state']); } $excelWriter = PHPExcel_IOFactory::createWriter($PHPExcelObj, 'Excel5'); $excelWriter->save('php://output'); exit();?> 中文文件名的伪静态规则怎么写? 求网站服务器定期执行的php文件 隐藏加密方法 上传多个图片的同时给图片加水印效果????? php连接mssql提示对象名无效!真么办啊? 请高手帮忙看一下,如何取出返回的XML的值 没办法,来求助:关于类的定义和调用的 有关URL REWRITE的问题,求助 如何用PHP获取用户键盘输入 一个查询语句返回多个记录集,怎么取后面的记录集的数据? 编程思路求教 调用popen执行程序时,返回错误 PHP老群邀请你加入
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=test.xls;");//导出的文件名
?>
<?php
$con = mysql_connect("localhost","root","mysql") or die("无法连接到数据库".mysql_error());
mysql_select_db('berecord');
mysql_query('set names utf8');$where = ' '.'1=1';
if ($_POST['name'] != ''){
$where.=" and name = '".$_POST['name']."'";
}
if($_POST['carnumber']!=''){
$where.=" and carnumber = '".$_POST['carnumber']."'";
}
if($_POST['do']!=''){
$where.=" and zhixing='".$_POST['do']."'";
}
if($_POST['usercode']!=''){
$where.="and usercode='".$_POST['usercode']."'";
}$sql="select * from record where".$where.' '."and searchtime between '$date1' and '$date2'";然后再用$row['']; 输出就可以了 不知道符不符合楼主要求
我给你一个完整的<?php
/*
* 文件创建时间 2010-8-26
*
* 创建人:森林
* 联系方式:QQ 83202700 Email:[email protected]
*/
if(!$_COOKIE[username]) exit("请登陆后导出数据");
header("Content-type:appliction/vnd.ms-excel");
header("content-disposition:filename=CW-YCL".date("Ymdhis").".xls");
include("data/conn.php");?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<body>
<TABLE cellSpacing=0 cellPadding=0 width="1000px" border=1>
<tr><td colspan=8><font size=5><b><center>EXCEL导出</center></b></font></td> </tr>
<tr><td colspan=8><center>半成品入库记录</center></td> </tr>
<tr><td colspan=8>制表日期:<?php echo date("Y-m-d")?>
</td></tr>
<tr>
<td>工令号</td>
<td>单据编号</td>
<td>料号</td>
<td>品名</td>
<td>数量</td>
<td>类型</td>
<td>日期</td>
<td>仓管操作员</td></tr>
</tr><?php$sqllld=mysql_query("SELECT * FROM `tyt_ckbcp_1` where dt>='$_POST[dtks]' && dt<='$_POST[dtjs]' order by id");
while($rowslld=mysql_fetch_array($sqllld)){ ?>
<tr><td style="vnd.ms-excel.numberformat:@"><?php echo $rowslld[gldh]?></td>
<td><?php echo $rowslld[bianhao]?></td>
<td><?php echo $rowslld[liaohao]?></td>
<td><?php echo $rowslld[pingm]?></td>
<td><?php echo $rowslld[sl]?></td>
<td><?php echo $rowslld[bz]?></td>
<td><?php echo $rowslld[dt]?></td>
<td><?php echo $rowslld[username]?></td>
</tr><?php
}
?></table>本报表最终由:<?php echo $_COOKIE[username]?> 导出
</body>
</head>
</html>
<?php$sql = "select * from shop ";
$query = mysql_query($sql);while($row = mysql_fetch_array($query)){
$rows[] = $row;
} header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=test.xlsx");
include 'PHPExcel.php'; //对文件的原子性操作类
include 'PHPExcel/IOFactory.php'; //顾名思义 以工厂模式封装的读写类 哈~
$PHPExcelObj = new PHPExcel(); $PHPExcelObj->setActiveSheetIndex(0); //在excel的第一张(Sheet1)表单上写入数据
$PHPExcelObj->getActiveSheet()->setCellValue('A1', '商品名称'); //A1是excel的 第1列第1行
$PHPExcelObj->getActiveSheet()->setCellValue('B1', '商品型号');
$PHPExcelObj->getActiveSheet()->setCellValue('C1', '商品数量');
$PHPExcelObj->getActiveSheet()->setCellValue('D1', '商品单价');
$PHPExcelObj->getActiveSheet()->setCellValue('E1', '商品用于');
$PHPExcelObj->getActiveSheet()->setCellValue('F1', '商品申请人');
$PHPExcelObj->getActiveSheet()->setCellValue('G1', '审批状态');
foreach($rows as $key=>$row){
$row_index = $key+2;
$PHPExcelObj->getActiveSheet()->setCellValue('A'.$row_index, $row['shop_name']); //A1是excel的 第1列第1行
$PHPExcelObj->getActiveSheet()->setCellValue('B'.$row_index, $row['shop_type']);
$PHPExcelObj->getActiveSheet()->setCellValue('C'.$row_index, $row['shop_shuliang']);
$PHPExcelObj->getActiveSheet()->setCellValue('D'.$row_index, $row['shop_value']);
$PHPExcelObj->getActiveSheet()->setCellValue('E'.$row_index, $row['shop_where']);
$PHPExcelObj->getActiveSheet()->setCellValue('F'.$row_index, $row['shop_shenqing']);
$PHPExcelObj->getActiveSheet()->setCellValue('G'.$row_index, $row['shop_state']);
}
$excelWriter = PHPExcel_IOFactory::createWriter($PHPExcelObj, 'Excel5');
$excelWriter->save('php://output');
exit();
?>
下面是这一页的内容
<?php$sql = "select * from shop ";
$query = mysql_query($sql);while($row = mysql_fetch_array($query)){
$rows[] = $row;
} header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=test.xlsx");
include 'PHPExcel.php'; //对文件的原子性操作类
include 'PHPExcel/IOFactory.php'; //顾名思义 以工厂模式封装的读写类 哈~
$PHPExcelObj = new PHPExcel(); $PHPExcelObj->setActiveSheetIndex(0); //在excel的第一张(Sheet1)表单上写入数据
$PHPExcelObj->getActiveSheet()->setCellValue('A1', '商品名称'); //A1是excel的 第1列第1行
$PHPExcelObj->getActiveSheet()->setCellValue('B1', '商品型号');
$PHPExcelObj->getActiveSheet()->setCellValue('C1', '商品数量');
$PHPExcelObj->getActiveSheet()->setCellValue('D1', '商品单价');
$PHPExcelObj->getActiveSheet()->setCellValue('E1', '商品用于');
$PHPExcelObj->getActiveSheet()->setCellValue('F1', '商品申请人');
$PHPExcelObj->getActiveSheet()->setCellValue('G1', '审批状态');
foreach($rows as $key=>$row){
$row_index = $key+2;
$PHPExcelObj->getActiveSheet()->setCellValue('A'.$row_index, $row['shop_name']); //A1是excel的 第1列第1行
$PHPExcelObj->getActiveSheet()->setCellValue('B'.$row_index, $row['shop_type']);
$PHPExcelObj->getActiveSheet()->setCellValue('C'.$row_index, $row['shop_shuliang']);
$PHPExcelObj->getActiveSheet()->setCellValue('D'.$row_index, $row['shop_value']);
$PHPExcelObj->getActiveSheet()->setCellValue('E'.$row_index, $row['shop_where']);
$PHPExcelObj->getActiveSheet()->setCellValue('F'.$row_index, $row['shop_shenqing']);
$PHPExcelObj->getActiveSheet()->setCellValue('G'.$row_index, $row['shop_state']);
}
$excelWriter = PHPExcel_IOFactory::createWriter($PHPExcelObj, 'Excel5');
$excelWriter->save('php://output');
exit();
?>