<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Heck's  Blog]]></title> 
<link>https://www.heckjj.com/index.php</link> 
<description><![CDATA[一瞬间的决定，往往可以改变很多，事实上，让自己成功的往往不是知识，是精神！ 如果你总是为自己找借口，那只好让成功推迟。执行力，今天！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Heck's  Blog]]></copyright>
<item>
<link>https://www.heckjj.com/php-Reader-Excel-file-html/</link>
<title><![CDATA[使用phpExcelReader读取excel文件]]></title> 
<author>Heck &lt;@hecks.tk&gt;</author>
<category><![CDATA[编程杂谈]]></category>
<pubDate>Mon, 20 Sep 2010 18:36:47 +0000</pubDate> 
<guid>https://www.heckjj.com/php-Reader-Excel-file-html/</guid> 
<description>
<![CDATA[ 
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 微软雅黑;">phpExcelReader是专门用来读取文件的。返回一个数组，包含表格的所有内容。<br/>该 class 使用的方法可以参考网站下载回来的压缩档中的 example.php。<br/>有几点要需要注意：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1、reader.php 中：将 <span style="color: #4169E1;"><strong>require_once 'Spreadsheet/Excel/Reader/OLERead.php';</strong></span>改为 <span style="color: #FF0000;"><strong>require_once 'oleread.inc';</strong></span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2、example.php 中：修改<span style="color: #4169E1;"><strong> $data->setOutputEncoding('CP1251');</strong></span>为 <span style="color: #FF1493;"><strong>$data->setOutputEncoding('CP936');</strong></span>或者是<span style="color: #4B0082;"><strong>$data->setOutputEncoding('gbk');</strong></span><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3、修改 <span style="color: #0000FF;"><strong>nl2br(htmlentities($data->sheets[$sheet]['cells'][$row][$col]));</strong></span>为 <span style="color: #008000;"><strong>$table_output[$sheet] .= nl2br(htmlspecialchars($data->sheets[$sheet]['cells'][$row][$col]));</strong></span><br/>不然中文会有问题。<br/>繁体的话可以修改为CP950、日文是CP932，具体可参考codepage说明。<br/>修改 $data->read('jxlrwtest.xls') 为自己的 excel 文件名，zip 档中附的 jxlrwtest.xls 应该是坏了。<br/>这是下载地址：<br/>phpExcelReader：<a href="http://sourceforge.net/projects/phpexcelreader/" target="_blank"><span style="color: #864f0e;">http://sourceforge.net/projects/phpexcelreader/</span></a><br/>PHPExcel：<a href="http://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=Documents&referringTitle=Home" target="_blank"><span style="color: #864f0e;">http://www.codeplex.com/PHPExcel/Wiki/View.aspx?title=Documents&referringTitle=Home</span></a><br/>范例代码一：</span><br/><textarea name="code" class="php" rows="15" cols="100">
<?php
require_once 'Excel/reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF-8');
$data->read('data.xls');
$rs = $data -> getExcelResult();
print_r($rs);
?>
</textarea><br/><span style="font-family: 微软雅黑;">首先下载 , 解压 phpExcelReader.zip<br/><br/>然后把 phpExcelReader&#92;Excel 下面的oleread.inc的代码都合并到 reader.php 并且 <br/>class Spreadsheet_Excel_Reader 代码在下方注释掉 require_once 'Spreadsheet/Excel/Reader/OLERead.php'; 这一行,然后在class Spreadsheet_Excel_Reader 里面加一个方法 </span><br/><textarea name="code" class="php" rows="15" cols="100">
function getExcelResult() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $result = array();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ($i = 1; $i <= $this->sheets[0]['numRows']; $i++) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for ($j = 1; $j <= $this->sheets[0]['numCols']; $j++) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $result[$i][$j] = $this->sheets[0]['cells'][$i][$j];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $result;
&#125;
</textarea><br/><span style="font-family: 微软雅黑;">范例代码二： </span><br/><textarea name="code" class="php" rows="15" cols="100">
<?php
require_once 'reader.php';
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('gbk');
//”data.xls”是指要导入到mysql中的excel文件
$data->read('data.xls');
@$db = mysql_connect('localhost', 'root', 'test') or die("Could not connect to database.");//连接数据库 
mysql_query("set names 'gbk'");//输出中文 
mysql_select_db('test'); //选择数据库
error_reporting(E_ALL ^ E_NOTICE);

for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++)&#123;&nbsp;&nbsp;&nbsp;&nbsp;
$sql = "INSERT INTO test VALUES('". $data->sheets[0]['cells'][$i][1]."','". $data->sheets[0]['cells'][$i][2]."')";
&nbsp;&nbsp; echo $sql.'<br />';
&nbsp;&nbsp; $res = mysql_query($sql);
&#125;
?>
</textarea><br/>Tags - <a href="https://www.heckjj.com/tags/php/" rel="tag">php</a> , <a href="https://www.heckjj.com/tags/%25E8%25AF%25BB%25E5%258F%2596/" rel="tag">读取</a> , <a href="https://www.heckjj.com/tags/excel/" rel="tag">excel</a>
]]>
</description>
</item><item>
<link>https://www.heckjj.com/php-Reader-Excel-file-html/#blogcomment</link>
<title><![CDATA[[评论] 使用phpExcelReader读取excel文件]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://www.heckjj.com/php-Reader-Excel-file-html/#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>