<?php
//建立reader对象 ,分别用两个不同的类对象读取2007和2003版本的excel文件
require("PHPExcel/Reader/Excel2007.php");
$filePath = "text.xlsx";
$PHPReader = new PHPExcel_Reader_Excel2007();
if( ! $PHPReader->canRead($filePath))
{
$PHPReader = new PHPExcel_Reader_Excel2007();
if( ! $PHPReader->canRead($filePath)){
echo 'no Excel';
return ;
}
}
$PHPExcel = $PHPReader->load($filePath); //读取文件
$currentSheet = $PHPExcel->getSheet(0); //读取第一个工作簿
$allColumn = $currentSheet->getHighestColumn(); // 所有列数
$allRow = $currentSheet->getHighestRow(); // 所有行数
$data = array(); //下面是读取想要获取的列的内容
for ($rowIndex = 2; $rowIndex <= $allRow; $rowIndex++)
{
$data[$cell = $currentSheet->getCell('A'.$rowIndex)->getValue()] = $currentSheet->getCell('B'.$rowIndex)->getValue();
}
var_dump($data);
foreach($data as $key=>$val){
$str = var_export($val,true);
file_put_contents("cross_yuanzheng_excel.php", "\r\n".'$cross_yuanzheng_arr['.$key.'] = '.$str.';',FILE_APPEND);
}
// $data = var_export($data,true);
?>
以下为转conf配置文件的示例
<?php
//从策划excel表中获得物品id、名称、type,导入前,需先删除非数据部分的文字说明和列标题,文件名不能包含汉字,删除id=99999的无用物品,用类型字段排序后,删除末尾的空白行,再开始导入
require_once( './include/class/Classes/PHPExcel/IOFactory.php');
//$filePath = $path.$_GET['f'];//从参数获得文件名
//$filePath = "PHPExcel.php";//从参数获得文件名
//$path = "E:\\susen\\myjob\\ddt\\";//固定文件目录
$filePath = 'alrale_languages.xlsx';//从参数获得文件名
$content_cn_str = null;
$content_vn_str = null;
$PHPExcel = PHPExcel_IOFactory::load($filePath);
$currentSheet = $PHPExcel->getSheet(0);
$allColumn = $currentSheet->getHighestColumn();
$allRow = $currentSheet->getHighestRow();
$str_arr = array();
for( $currentRow = 2 ; $currentRow <= $allRow ; $currentRow++) {
$row_arr = array();
for ($currentColumn = 'A'; ord($currentColumn) <= ord($allColumn); $currentColumn++) {
$address = $currentColumn . $currentRow;
$string = $currentSheet->getCell($address)->getValue();
if ($string === '')
break;
switch ($currentColumn) {
case "A":
$flag = "catalog";
break;
case "B":
$flag = "file";
break;
case "C":
$flag = "name";
break;
case "D":
$flag = "cn";
break;
case "E":
$flag = "vn"; break; } $row_arr[$flag] = "$string"; } //一级目录 $new_cn_dir = $row_arr['catalog'].'/cn/'; $new_vn_dir = $row_arr['catalog'].'/vn/'; if(!is_dir($new_cn_dir) || !is_dir($new_cn_dir)){ mkdir(iconv("UTF-8", "GBK", $new_cn_dir),0777,true); mkdir(iconv("UTF-8", "GBK", $new_vn_dir),0777,true); } $new_cn_file = $row_arr['catalog'].'/cn/'.$row_arr['file'].'.conf'; $new_vn_file = $row_arr['catalog'].'/vn/'.$row_arr['file'].'.conf'; if(file_exists($new_cn_file) || file_exists($new_vn_file)){ unlink($new_cn_file ); unlink($new_vn_file ); } //$content_str = null; $content_cn_str .= "$row_arr[name]=$row_arr[cn]\n"; $content_vn_str .= "$row_arr[name]=$row_arr[vn]\n";} file_put_contents($new_cn_file,$content_cn_str,FILE_APPEND); file_put_contents($new_vn_file,$content_vn_str,FILE_APPEND);echo "44:ok!";