php php从excel表中读取数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14352791/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Read data from excel sheet in php
提问by please delete me
I am using this code for reading data from any file but if i want to read data from excel sheet then what should i do?
我正在使用此代码从任何文件中读取数据,但如果我想从 Excel 表中读取数据,我该怎么办?
<?php
if(isset($_POST['submit'])){
$cir="certificate";
if(!is_dir($cir)){
mkdir($cir);
}
$image1=$_FILES['cir']['name'];
$image=$_FILES['cir']['tmp_name'];
$server_path=$cir.'/'.basename($_FILES['cir']['name']);
$s=move_uploaded_file($image,$server_path);
if($s){
//echo "successfully uploaded.";
$file_open=fopen("$cir/$image1","r");
$file_read=fread($file_open,filesize("$cir/$image1"));
echo $file_read;
//$data = substr(strrchr("$cir/$file_read", ","),5 );
echo $file_read;
}else{
echo "problem in uploading.";
}
}
?>
<html>
<body>
<form name="form" method="post" enctype="multipart/form-data">
<input type="file" name="cir" /><br />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
Excel sheet containing various shells like Name-XYZ, s.no-123 etc. I want that xyz should be put on a variable and 123 should be on another variable. What will be code in PHP?
Excel 表包含各种外壳,如 Name-XYZ、s.no-123 等。我希望 xyz 应该放在一个变量上,而 123 应该放在另一个变量上。PHP 中的代码是什么?
回答by SachinGutte
If your site involves reading excel files extensively then go for a library like https://github.com/PHPOffice/PHPExcel. It supports both xls and xlsx types.
如果您的网站涉及广泛阅读 excel 文件,那么请使用https://github.com/PHPOffice/PHPExcel 之类的库。它支持 xls 和 xlsx 类型。

