Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial phpExcel导出excel的两个问题

phpExcel导出excel的两个问题

Jun 23, 2016 pm 02:21 PM

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); ?>
Copy after login

第二个问题: 内存超出 
解决办法一:
可以通过以下两个方法修改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 of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles