PHP-php自动生成excel
php自动生成excel,不用手动点击保存路径。用phpexcel有相关设置吗,或者其他的方法??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
php自动生成excel,不用手动点击保存路径。用phpexcel有相关设置吗,或者其他的方法??
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
给你使用PHPExcel的一个实例:
require_once WEB_PATH.'/common/class/PHPExcel.1.7.7/PHPExcel.php';
require_once WEB_PATH.'/common/class/PHPExcel.1.7.7/PHPExcel/Writer/Excel5.php';
$objPHPExcel = new PHPExcel();
// 添加 标题
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
$objPHPExcel->getActiveSheet()->setCellValue('B1', iconv("gbk","utf-8",'捐款类型'));
$objPHPExcel->getActiveSheet()->setCellValue('C1', iconv("gbk","utf-8",'区域'));
$objPHPExcel->getActiveSheet()->setCellValue('D1', iconv("gbk","utf-8",'捐款编号'));
$objPHPExcel->getActiveSheet()->setCellValue('E1', iconv("gbk","utf-8",'捐助学生'));
$objPHPExcel->getActiveSheet()->setCellValue('F1', iconv("gbk","utf-8",'E网论坛ID'));
$objPHPExcel->getActiveSheet()->setCellValue('G1', iconv("gbk","utf-8",'真实姓名'));
$objPHPExcel->getActiveSheet()->setCellValue('H1', iconv("gbk","utf-8",'联系方式'));
$objPHPExcel->getActiveSheet()->setCellValue('I1', iconv("gbk","utf-8",'是否愿意看望'));
$objPHPExcel->getActiveSheet()->setCellValue('J1', iconv("gbk","utf-8",'是否愿意长期结对'));
$objPHPExcel->getActiveSheet()->setCellValue('K1', iconv("gbk","utf-8",'捐款金额(元)'));
$objPHPExcel->getActiveSheet()->setCellValue('L1', iconv("gbk","utf-8",'捐款时间'));
// 循环添加 数据
for( $i=0, $j=2; $i<count($donationList); $i++,$j++ ){
$objPHPExcel->getActiveSheet()->setCellValue('A'.$j, $donationList[$i]['id']);
if( $donationList[$i]['ifalipay']==1 ){ $jkType = '线上(支付宝)'; }else{ $jkType = '线下'; }
$objPHPExcel->getActiveSheet()->setCellValue('B'.$j, iconv("gbk","utf-8",$jkType));
$objPHPExcel->getActiveSheet()->setCellValue('C'.$j, iconv("gbk","utf-8",$classes[$donationList[$i]['classes']]));
$objPHPExcel->getActiveSheet()->setCellValue('D'.$j, $donationList[$i]['donnum']);
$objPHPExcel->getActiveSheet()->setCellValue('E'.$j, iconv("gbk","utf-8",$donationList[$i]['stuname']));
$objPHPExcel->getActiveSheet()->setCellValue('F'.$j, iconv("gbk","utf-8",$donationList[$i]['bbsusername']));
$objPHPExcel->getActiveSheet()->setCellValue('G'.$j, iconv("gbk","utf-8",$donationList[$i]['realname']));
$objPHPExcel->getActiveSheet()->setCellValue('H'.$j, $donationList[$i]['tel']);
if( $donationList[$i]['ifvisit']==1 ){ $ifLook = '愿意'; }else{ $ifLook = '不愿意'; }
$objPHPExcel->getActiveSheet()->setCellValue('I'.$j, iconv("gbk","utf-8",$ifLook));
if( $donationList[$i]['iflongtime']==1 ){ $iflongtime = '愿意'; }else{ $iflongtime = '不愿意'; }
$objPHPExcel->getActiveSheet()->setCellValue('J'.$j, iconv("gbk","utf-8",$iflongtime));
$objPHPExcel->getActiveSheet()->setCellValue('K'.$j, $donationList[$i]['money']);
$objPHPExcel->getActiveSheet()->setCellValue('L'.$j, $donationList[$i]['time']);
}
// Excel 5 file 保存
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
$objWriter->save(APP_PATH."/xls/gognyi_{$fileClassName}_{$timeY}{$timeM}.xls");