php读取excel数据 php读取xlsx

php读取excel,excel下多个个工作表,该怎么读取php有个PHPExcel扩展php读取excel数据,是可以实现php读取excel数据你的要求的 。
php读取excel数据我这里有个可以读取多个工作薄的自定义excel类php读取excel数据,试试看:
?php
/**
*excel.class.php
*/
class Excel
{
/**
* 从excel文件中取得所有数据 。并转换成指定编码格式 。
* $toCode 表示需要转换成的编码格式,目前扩充了utf8,gbk2312,html三种格式 。
* @return 返回二维数组 。
*/
static function getDataFromExl($filePath,$toCode = "utf8")
{
$fh = @fopen($filePath,'rb');
if( !$fh || filesize($filePath)==0 )
{
return -1;//文件不可读或者为空
}
$fc = fread( $fh, filesize($filePath) );
@fclose($fh);
if( strlen($fc)filesize($filePath) )
{
return -2;//读取错误
}
$exc = new ExcelFileParser();
$res = $exc-ParseFromString($fc);
$ws_number = count($exc-worksheet['name']);//取得工作薄数量
if( $ws_number1 )
{
return -3;
}
for ($ws_n = 0; $ws_n$ws_number; $ws_n)
{
$ws = $exc - worksheet['data'][$ws_n];
$data = https://www.04ip.com/post/$ws['cell'];
foreach($data as $k=$v)//一行数据
{
$row = null;
foreach($v as $a=$d)//一行数据的一个字节
{
$value = https://www.04ip.com/post/null;
if(count($d) == 1)
{
continue;
}
if($d['type'] == 0)//如果是字符类型则转换成为指定编码格式
{
$ind = $d['data'];
if( $exc-sst['unicode'][$ind] ) //返回数据编码格式
{
switch($toCode)
{
case "utf8":
$s = Strings::uc2utf8($exc-sst['data'][$ind]);
break;
case "gbk":
$s = Strings::uc2gbk($exc-sst['data'][$ind]);
break;
case "html":
$s = Strings::uc2html($exc-sst['data'][$ind]);
break;
default:
$s = Strings::uc2utf8($exc-sst['data'][$ind]);
break;
}
}
else
{
$s = $exc-sst['data'][$ind];
}
if( strlen(trim($s))==0 || $s === null )
{
$valuehttps://www.04ip.com/post/= '';
}
else
{
$value = https://www.04ip.com/post/$s;
}
}
elseif($d['type'] == 3)
{
$time_list= explode('.', $d['data']);
$time_format = $time_list[2].'-'.$time_list[0].'-'.$time_list[1];
$timestamp = strtotime($time_format);
$value = https://www.04ip.com/post/date("Y-m-d H:i:s", $timestamp);
}
else
{
$value = https://www.04ip.com/post/$d['data'];
}
$row[$a] = $value;
}
$recordList[] = $row;
}
}
return $recordList;
}
}
require_once('./excel.class.php');
$emailData = https://www.04ip.com/post/Excel::getDataFromExl($_FILES['file_name']['tmp_name']);
PHP远程读取excel文件,怎么读取PHPExcel 通过 PHPExcel_Shared_OLERead 类的 read 方法读取文件
但 read 方法里使用了 is_readable 函数来确认文件是否存在,而 is_readable 不能作用于 url
所以不可直接远程读取
但若绕过 is_readable 函数的话,就是可以的
public function read($sFileName)
{
// Check if file exists and is readable
if(!is_readable($sFileName)) {
throw new Exception("Could not open " . $sFileName . " for reading! File does not exist, or it is not readable.");
}
// Get the file data
$this-data = https://www.04ip.com/post/file_get_contents($sFileName);
php怎么读取excel 文件数据并输出PHPExcel
PHPExcel 是用来操作Office Excel 文档的一个PHP类库,它基于微软的OpenXML标准和PHP语言 。可以使用它来读取、写入不同格式的电子表格,如 Excel (BIFF) .xls, Excel 2007 (OfficeOpenXML) .xlsx, CSV, Libre/OpenOffice Calc .ods, Gnumeric, PDF, HTML等等 。
PHP读取示例代码
//获取上传的excel临时文件
$path = $_FILES["file"]["tmp_name"];
//将临时文件移动当前目录,可自定义存储位置
move_uploaded_file($_FILES["file"]["tmp_name"],$_FILES["file"]["name"]);
//将获取在服务器中的Excel文件,此处为上传文件名
$path = $_FILES["file"]["name"];
//调用readExcel函数返回一个
二维数组
$exceArray = readExcel($path);
//创建一个读取
excel函数
function readExcel($path){
//引入PHPExcel类库
include 'Classes/PHPExcel.php';
include 'Classes/PHPExcel/IOFactory.php';
$type = 'Excel5';//设置为Excel5代表支持2003或以下版本,
Excel2007代表2007版
$xlsReader = \PHPExcel_IOFactory::createReader($type);
$xlsReader-setReadDataOnly(true);
$xlsReader-setLoadSheetsOnly(true);
$Sheets = $xlsReader-load($path);
//开始读取上传到服务器中的Excel文件,返回一个
二维数组
$dataArray = $Sheets-getSheet(0)-
toArray();
return $dataArray;
}
用php读取excel,并将结果写入mysql,怎么做用php读取excel,并将结果写入mysql
?php
$workbook
=
"D:\\www\\xtwh\\B01\\mysingle.xls";
$sheet
=
"list";
#实例化一个组件的对象
$ex
=
new
COM("Excel.sheet")
or
Die
("Did
not
connect");
#打开工作本使我们可使用它
$wkb
=
$ex-application-Workbooks-Open($workbook)
or
Die
("Did
not
open");
#读单元格数据
$sheets
=
$wkb-Worksheets($sheet);
#Select
the
sheet
$sheets-activate;
#Activate
it
//$cell-activate;
#Activate
the
cell
.If
this,
you
can
modify
the
cell
data.
for($i=2;$i=2501;$i)
{
$a=$sheets-Cells($i,A);
if($a-value
==
"last")
break;
$b=$sheets-Cells($i,B);
$bp[]=$b-value;
$c=$sheets-Cells($i,C);
$cp[]=$c-value;
$d=$sheets-Cells($i,D);
$dp[]=$d-value;
$e=$sheets-Cells($i,E);
$ep[]=$e-value;
$f=$sheets-Cells($i,F);
$fp[]=$f-value;
$g=$sheets-Cells($i,G);
$gp[]=$g-value;
$h=$sheets-Cells($i,H);
$hp[]=$h-value;
}
$ex-application-ActiveWorkbook-Close("False");
unset
($ex);
require_once("../../conn.php");
$sql0="DELETE
FROM
`newyonghu`";
$result0=mysql_query($sql0,$mylink);
mysql_free_result($result0);
for($i=0;$icount($bp);$i)
{
$sql="INSERT
INTO
`newyonghu`
(`name`,
`dept`,
`team`,
`group01`,
`position`,
`mingzi`,
`single`,
`info`)
VALUES
('".$bp[$i]."',
'".$fp[$i]."',
'".$dp[$i]."',
'".$ep[$i]."',
'".$gp[$i]."',
'".$cp[$i]."',
'".$hp[$i]."',
'single');";
$result=mysql_query($sql,$mylink);
}
echo
"script
language=\"Javascript\"";
echo
"window.close()";
echo
"/script";
mysql_free_result($result);
//释放结果内存资源
mysql_close($mylink);
//
断开连接
?
【php读取excel数据 php读取xlsx】php读取excel数据的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php读取xlsx、php读取excel数据的信息别忘了在本站进行查找喔 。

    推荐阅读