一个最简单phpExcel导出的例子,麻烦指点一下?
php版本 5.2 线程安全 vc6
服务器:apache2.2 线程 模块加载方式(CLI)
其他页面运转正常
废话少说,excel的导出代码,最简单的测试代码,但是下载以后打开提示如下
重新命名无效的工作表名称。
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php require_once($_SERVER['DOCUMENT_ROOT'] ."/inc/phpexcel/PHPExcel.php");require_once($_SERVER['DOCUMENT_ROOT'] ."/inc/phpexcel/PHPExcel/Writer/Excel5.php");// 创建一个处理对象实例 $objExcel = new PHPExcel(); $objExcel->setActiveSheetIndex(0); $objActSheet = $objExcel->getActiveSheet(); //设置当前活动sheet的名称 $objActSheet->setTitle(iconv('utf-8','gbk', "测试工作pu名字")); //ROW 1$objActSheet->setCellValueByColumnAndRow(1,2,iconv('utf-8','gbk', "测试"));//ROW 2//ROW 3//获取数据 //在浏览器导出header("Content-Type: application/force-download");header('Content-Type: application/vnd.ms-excel');header("Content-Disposition: attachment;filename=\"导出查询.xls\"");header('Cache-Control: max-age=0');header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: no-cache"); // 创建文件格式写入对象实例, uncomment $objWriter = new PHPExcel_Writer_Excel5($objExcel); //到文件 $objWriter->save("php://output"); ?>
------解决方案--------------------
require('config.php');//加载配置文
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ('Content-type: application/x-msexcel');
header ("Content-Disposition: attachment; filename=weibo.xls" );
header ("Content-Description: PHP/INTERBASE Generated Data" );
//
// the next lines demonstrate the generation of the Excel stream
//
$content = $db->getList("select * from weibo_baidu");
$num = count($content);
/*echo $num;
foreach($content as $k=>$contents){
echo $aa=$k+1;
echo "
";
//echo $contents['b_title']."
";
}*/
xlsBOF(); // begin Excel stream
xlsWriteLabel(0, 0,iconv("UTF-8", "GBK",序号) );
xlsWriteLabel(0, 1,iconv("UTF-8", "GBK",发布者));
xlsWriteLabel(0, 2,iconv("UTF-8", "GBK",内容概要) );
xlsWriteLabel(0, 3,iconv("UTF-8", "GBK",URl));
xlsWriteLabel(0, 4,iconv("UTF-8", "GBK",来源));
xlsWriteLabel(0, 5,iconv("UTF-8", "GBK",抓取日期));
foreach($content as $k=>$contents){
$i=$k+1;
xlsWriteLabel($i, 0, $i);
xlsWriteLabel($i, 1, iconv("UTF-8", "GBK",$contents['b_title']));
xlsWriteLabel($i, 2, iconv("UTF-8", "GBK",$contents['b_info']));
xlsWriteLabel($i, 3, iconv("UTF-8", "GBK",$contents['b_url']));
xlsWriteLabel($i, 4, iconv("UTF-8", "GBK",$contents['b_source']));
xlsWriteLabel($i, 5, iconv("UTF-8", "GBK",$contents['b_tiem']));
}
xlsEOF(); // close the stream
// ----- begin of function library -----
// Excel begin of file header
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
// Excel end of file footer
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
// Function to write a Number (double) into Row, Col
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version
Chinese version, very easy to use

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
