search
HomeBackend DevelopmentPHP TutorialphpExcel导出excel的两个问题

Notice: iconv_strlen() [function.iconv-strlen]: Detected an illegal character in input string in E:\test\PHPnow-1.5.6\vhosts\127.0.0.18\inc\PHPExcel\PHPExcel\Shared\String.php on line 554

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 16 bytes) in E:\test\PHPnow-1.5.6\vhosts\127.0.0.18\inc\PHPExcel\PHPExcel\Cell.php on line 840

本地调试的时候出现的,请问该怎么解决呢? phpexcel默认导出的编码是什么呢?数据库的编码是GBK的。
源代码有500多行(菜鸟PHPER)就不贴了。
针对第二个问题在网上找了下,加了这两句还是没用
set_time_limit(900);
//设置最大内存为128M
@ini_set('memory_limit','128M');

在这里先谢谢大家了


回复讨论(解决方案)

??1:
Mb_convert_encoding($html,'UTF8','BIG5'); //?big5??utf8
或iconv(gb2312,UTF-8,$要转的string);

??2:
你的?存不足,需要修改PHP.ini中允?使用的?存量,改完重?apache

??1:
Mb_convert_encoding($html,'UTF8','BIG5'); //?big5??utf8
或iconv(gb2312,UTF-8,$要转的string);

??2:
你的?存不足,需要修改PHP.ini中允?使用的?存量,改完重?apache
你好,第一个问题解决了
但第二问题依然还在,我在测试的时候用了@ini_set('memory_limit', '-1');还是出现
Fatal error: Out of memory (allocated 1602748416) (tried to allocate 134217728 bytes) in E:\test\PHPnow-1.5.6\vhosts\127.0.0.18\inc\PHPExcel\PHPExcel\Cell.php on line 839
但是我本地的内存已经用满了,虾米那是我的代码

<?phpsession_start();include("inc/func.php");$conn=mysql_connect('localhost','root','123456');mysql_select_db('gzlgl',$conn);mysql_query("set names UTF8");//导入类库require_once 'inc/PHPExcel/PHPExcel.php'; require_once 'inc/PHPExcel/PHPExcel/IOFactory.php';//require_once '../inc/PHPExcel/PHPExcel/Reader/Excel5.php';require_once 'inc/PHPExcel/PHPExcel/Writer/Excel2007.php';//设置最大执行时间set_time_limit(0);//设置最大内存为128M@ini_set('memory_limit', '-1'); /*初始化*/$arr_sem=array();$sql="select * from semester";//读入学期周数$record=mysql_query($sql,$conn) or die(mysql_error());$row=mysql_fetch_row($record);do{ $arr_sem["$row[0]"]=$row[1];//arr_sem['学期']=学期周数}while($row=mysql_fetch_row($record));$arr_theory=array();//理论课工作量数组//$arr_total_theory=array();//理论课工作量数组$arr_lab=array();//实验课工作量数组//$arr_total_lab=array();//实验课工作量数组$arr_add=array();//附加工作量数组//$arr_total_add=array();//附加工作量数组$arr_total=array();//全部工作量数组//导出为excel,考虑到兼容问题,导出为xls文件// 创建一个处理对象实例$objExcel = new PHPExcel();// 创建文件格式写入对象实例//$objWriter = new PHPExcel_Writer_Excel5($objExcel);$objWriter = new PHPExcel_Writer_Excel2007($objExcel); // 用于 2007 格式$objWriter->setOffice2003Compatibility(true);//设置文档基本属性$objProps = $objExcel->getProperties();$objProps->setCreator("Tao Hu");$objProps->setLastModifiedBy("ddd");$objProps->setTitle(iconv('gbk', 'utf-8', '所选时间内的工作量详情'));$objProps->setSubject("dd");$objProps->setDescription("ss");$objProps->setKeywords("s");$objProps->setCategory("ss");//设置当前的sheet索引,用于后续的内容操作。//一般只有在使用多个sheet的时候才需要显示调用。//缺省情况下,PHPExcel会自动创建第一个sheet被设置SheetIndex=0$objExcel->setActiveSheetIndex(0);$objActSheet = $objExcel->getActiveSheet();//设置当前活动sheet的名称$objActSheet->setTitle('ddd');$cacheMethod = PHPExcel_CachedObjectStorageFactory:: cache_to_phpTemp;  $cacheSettings = array( ' memoryCacheSize '  => '8MB'                        );  PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings); //合并单元格$i=1;//行号$j='A';//列号	//合并单元格	$objActSheet->mergeCells("'A'.$i.':L'.$i");	$objActSheet->setCellValue("'A'.$i", '理论课工作量');	$i++;	//各项标题	$objActSheet->setCellValue("'A'.$i", '工作量编号');	$objActSheet->setCellValue("'B'.$i", '学期');	$objActSheet->setCellValue("'C'.$i", '课程名称');	$objActSheet->setCellValue("'D'.$i", '教师名称');	$objActSheet->setCellValue("'E'.$i", 'K1');	$objActSheet->setCellValue("'F'.$i", 'K2');	$objActSheet->setCellValue("'G'.$i", 'K3');	$objActSheet->setCellValue("'H'.$i", '学生数');	$objActSheet->setCellValue("'I'.$i", 'we');	$objActSheet->setCellValue("'J'.$i", 'we');	$objActSheet->setCellValue("'K'.$i", 'fds');	$objActSheet->setCellValue("'L'.$i", 'fwe');	$i++;		$objActSheet->setCellValue("'A'.$i", "dfd");		$objActSheet->setCellValue("'B'.$i", "dfd");	    $objActSheet->setCellValue("'C'.$i", "dfd");		$objActSheet->setCellValue("'D'.$i", "dfd");		$objActSheet->setCellValue("'E'.$i", "dfd");		$objActSheet->setCellValue("'F'.$i", "dfd");		$objActSheet->setCellValue("'G'.$i", "dfd");		$objActSheet->setCellValue("'H'.$i", "dfd");		$objActSheet->setCellValue("'I'.$i", "dfd");		$objActSheet->setCellValue("'J'.$i", "dfd");		$objActSheet->setCellValue("'K'.$i", $has_exam);		$objActSheet->setCellValue("'L'.$i", $sum_thoery);		$i++;//输出内容$outputFileName = "output.xls";$objWriter->save($outputFileName); ?>

第二个问题: 内存超出 
解决办法一:
可以通过以下两个方法修改php运行时的内存限制.
在php.ini文件里设置memory_limit = 12M(推荐使用,如果拥有这个权限的话)
?在sites/default/settings.php文件里设置ini_set('memory_limit','12M');
解决办法二:
// 设置缓存方式,减少对内存的占用
$cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
$cacheSettings = array (
'cacheTime' => 300 
);
PHPExcel_Settings::setCacheStorageMethod ( $cacheMethod, $cacheSettings );

第二个问题: 内存超出 
解决办法一:
可以通过以下两个方法修改php运行时的内存限制.
在php.ini文件里设置memory_limit = 12M(推荐使用,如果拥有这个权限的话)
?在sites/default/settings.php文件里设置ini_set('memory_limit','12M');
解决办法二:
// 设置缓存方式,减少对内存的……
已经设置为1024M了还是提示这个错误
而且使用的时候电脑内存占用超高,直接卡机

很正常,尝试输出页面占用内存情况,你就会懂得  echo memory_get_usage ();
在我本机,load一个5MB左右的excel文件,消耗了188 MB内容,而且页面用了二十秒。
http://bbs.csdn.net/topics/390312724

引用 3 楼 wodecuoshi230 的回复:第二个问题: 内存超出 
解决办法一:
可以通过以下两个方法修改php运行时的内存限制.
在php.ini文件里设置memory_limit = 12M(推荐使用,如果拥有这个权限的话)
?在sites/default/settings.php文件里设置ini_set('memory_limit','12M');
…… 更改php.ini内存限制之后,要重启apache

引用 4 楼 hu5487 的回复:引用 3 楼 wodecuoshi230 的回复:第二个问题: 内存超出 
解决办法一:
可以通过以下两个方法修改php运行时的内存限制.
在php.ini文件里设置memory_limit = 12M(推荐使用,如果拥有这个权限的话)
?在sites/default/settings.php文件里设置ini_set('memo……
都重启了
加上之后出现
589704
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 35 bytes) in E:\test\PHPnow-1.5.6\vhosts\127.0.0.18\inc\PHPExcel\PHPExcel\Cell.php on line 839

引用 6 楼 wodecuoshi230 的回复:引用 4 楼 hu5487 的回复:引用 3 楼 wodecuoshi230 的回复:第二个问题: 内存超出 
解决办法一:
可以通过以下两个方法修改php运行时的内存限制.
在php.ini文件里设置memory_limit = 12M(推荐使用,如果拥有这个权限的话)
?在sites/default/setti…… ?是不?用,??加大

好像里面有一个设置编码的吧,我用的时候就是把编码设置成utf-8就可以了


phpExcel大数据量情况下内存溢出解决

引用 7 楼 hu5487 的回复:引用 6 楼 wodecuoshi230 的回复:引用 4 楼 hu5487 的回复:引用 3 楼 wodecuoshi230 的回复:第二个问题: 内存超出 
解决办法一:
可以通过以下两个方法修改php运行时的内存限制.
在php.ini文件里设置memory_limit = 12M(推荐使用,如果拥有这个权限的话)
?在s……
加到2G还是不行 
有没有轻量级的呢?  我需要3个循环的 这才一个循环就这样了 到时候没那么给力的机器装。。。设置了缓存也不行。。。而且速度太慢了

phpExcel大数据量情况下内存溢出解决
使用了方法依然解决不了

引用 8 楼 sibang 的回复:引用 7 楼 hu5487 的回复:引用 6 楼 wodecuoshi230 的回复:引用 4 楼 hu5487 的回复:引用 3 楼 wodecuoshi230 的回复:第二个问题: 内存超出 
解决办法一:
可以通过以下两个方法修改php运行时的内存限制.
在php.ini文件里设置memory_limit = 12M(推荐使…… 把你的php代?循?方式修改成url循环方式,示例:

$i=(!isset($_GET['i'])) ? 0 : $_GET['i'];
....
select * from 表 where id>{$i} order by id asc limit 0,1
....
Header('Location:?i='.$i);

引用 11 楼 hu5487 的回复:引用 8 楼 sibang 的回复:引用 7 楼 hu5487 的回复:引用 6 楼 wodecuoshi230 的回复:引用 4 楼 hu5487 的回复:引用 3 楼 wodecuoshi230 的回复:第二个问题: 内存超出 
解决办法一:
可以通过以下两个方法修改php运行时的内存限制.
在php.ini文件里设置mem……
研究了半天问题终于解决了,是我的代码的问题,有几个格式用错了,比如 $objActSheet->mergeCells("'A'.$i.':L'.$i");错了导致根本过不去

引用 13 楼 sibang 的回复:引用 11 楼 hu5487 的回复:引用 8 楼 sibang 的回复:引用 7 楼 hu5487 的回复:引用 6 楼 wodecuoshi230 的回复:引用 4 楼 hu5487 的回复:引用 3 楼 wodecuoshi230 的回复:第二个问题: 内存超出 
解决办法一:
可以通过以下两个方法修改php运行时的内存限制…… 恭喜,???


引用 11 楼 hu5487 的回复:引用 8 楼 sibang 的回复:引用 7 楼 hu5487 的回复:引用 6 楼 wodecuoshi230 的回复:引用 4 楼 hu5487 的回复:引用 3 楼 wodecuoshi230 的回复:第二个问题: 内存超出 
解决办法一:
可以通过以下两个方法修改php运行时的内存限制.
在php.ini文件里设置mem……
研究了半天问题终于解决了,是我的代码的问题,有几个格式用错了,比如 $objActSheet->mergeCells("'A'.$i.':L'.$i");错了导致根本过不去
弱弱的问一句,正确的表示方法是?

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the difference between unset() and session_destroy()?What is the difference between unset() and session_destroy()?May 04, 2025 am 12:19 AM

Thedifferencebetweenunset()andsession_destroy()isthatunset()clearsspecificsessionvariableswhilekeepingthesessionactive,whereassession_destroy()terminatestheentiresession.1)Useunset()toremovespecificsessionvariableswithoutaffectingthesession'soveralls

What is sticky sessions (session affinity) in the context of load balancing?What is sticky sessions (session affinity) in the context of load balancing?May 04, 2025 am 12:16 AM

Stickysessionsensureuserrequestsareroutedtothesameserverforsessiondataconsistency.1)SessionIdentificationassignsuserstoserversusingcookiesorURLmodifications.2)ConsistentRoutingdirectssubsequentrequeststothesameserver.3)LoadBalancingdistributesnewuser

What are the different session save handlers available in PHP?What are the different session save handlers available in PHP?May 04, 2025 am 12:14 AM

PHPoffersvarioussessionsavehandlers:1)Files:Default,simplebutmaybottleneckonhigh-trafficsites.2)Memcached:High-performance,idealforspeed-criticalapplications.3)Redis:SimilartoMemcached,withaddedpersistence.4)Databases:Offerscontrol,usefulforintegrati

What is a session in PHP, and why are they used?What is a session in PHP, and why are they used?May 04, 2025 am 12:12 AM

Session in PHP is a mechanism for saving user data on the server side to maintain state between multiple requests. Specifically, 1) the session is started by the session_start() function, and data is stored and read through the $_SESSION super global array; 2) the session data is stored in the server's temporary files by default, but can be optimized through database or memory storage; 3) the session can be used to realize user login status tracking and shopping cart management functions; 4) Pay attention to the secure transmission and performance optimization of the session to ensure the security and efficiency of the application.

Explain the lifecycle of a PHP session.Explain the lifecycle of a PHP session.May 04, 2025 am 12:04 AM

PHPsessionsstartwithsession_start(),whichgeneratesauniqueIDandcreatesaserverfile;theypersistacrossrequestsandcanbemanuallyendedwithsession_destroy().1)Sessionsbeginwhensession_start()iscalled,creatingauniqueIDandserverfile.2)Theycontinueasdataisloade

What is the difference between absolute and idle session timeouts?What is the difference between absolute and idle session timeouts?May 03, 2025 am 12:21 AM

Absolute session timeout starts at the time of session creation, while an idle session timeout starts at the time of user's no operation. Absolute session timeout is suitable for scenarios where strict control of the session life cycle is required, such as financial applications; idle session timeout is suitable for applications that want users to keep their session active for a long time, such as social media.

What steps would you take if sessions aren't working on your server?What steps would you take if sessions aren't working on your server?May 03, 2025 am 12:19 AM

The server session failure can be solved through the following steps: 1. Check the server configuration to ensure that the session is set correctly. 2. Verify client cookies, confirm that the browser supports it and send it correctly. 3. Check session storage services, such as Redis, to ensure that they are running normally. 4. Review the application code to ensure the correct session logic. Through these steps, conversation problems can be effectively diagnosed and repaired and user experience can be improved.

What is the significance of the session_start() function?What is the significance of the session_start() function?May 03, 2025 am 12:18 AM

session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use