本文整理汇总了PHP中PHPExcel_Reader_Excel5类的典型用法代码示例。如果您正苦于以下问题:PHP PHPExcel_Reader_Excel5类的具体用法?PHP PHPExcel_Reader_Excel5怎么用?PHP PHPExcel_Reader_Excel5使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PHPExcel_Reader_Excel5类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importCartshop
static function importCartshop($tmp_file, $file, &$out)
{
global $CONFIG, $ST;
$dir = 'shared/php/';
include "{$dir}PHPExcel.php";
include "{$dir}PHPExcel/IOFactory.php";
PHPExcel_Settings::setLocale('ru');
if (file_ext($file) == 'xlsx') {
$objReader = new PHPExcel_Reader_Excel2007();
} elseif (file_ext($file) == 'xls') {
$objReader = new PHPExcel_Reader_Excel5();
}
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($tmp_file);
/*$objPHPExcel->setActiveSheetIndex(0);
$objWorksheet = $objPHPExcel->getActiveSheet();
$keys=array();
$keys_flg=array('category_id'=>'id',
'parent_id'=>'parentid',
'name'=>'name',
'description'=>'description',
'image_name'=>'img',
'sort_order'=>'main_sort',
);
$out=array();
foreach ($objWorksheet->getRowIterator() as $row) {
$data=array();
$field=array();
$field_ext=array();
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
$fld_flg=false;//Строка поля
$no_user_itm='';
foreach ($cellIterator as $cell) {
$val=trim(u2w($cell->getValue()));
if(!$fld_flg && $val=='category_id'){
$fld_flg=true;
}
if($fld_flg){//Грузим поля
if(isset($keys_flg[$val])){
$keys[$cell->getColumn()]=$keys_flg[$val];
}
// print_r($keys);
continue;
}
if($keys && isset($keys[$cell->getColumn()])){
if(is_integer($keys[$cell->getColumn()])){
$field["{$keys[$cell->getColumn()]}"]=$val;
}else{
$field_ext["{$keys[$cell->getColumn()]}"]=$val;
}
}
}
if(!$keys){
continue;
}
if(!empty($field_ext['id'])){
if($field_ext['img']){
if($img=@file_get_contents('http://www.farmcosmetica.ru/image/'.$field_ext['img'])){
$img_name=preg_replace('|^data/|','',$field_ext['img']);
$img_name=str_replace('/','_',$img_name);
$img_name="storage/catalog/".$img_name;
if(!file_exists($img_name)){
file_put_contents($img_name,$img);
}
$field_ext['img']="/".$img_name;
}else{
$field_ext['img']="";
}
}
$rs=$ST->select("SELECT * FROM sc_shop_catalog WHERE id={$field_ext['id']}");
if($rs->next()){
$ST->update('sc_shop_catalog',$field_ext,"id={$field_ext['id']}");
}else{
$ST->insert('sc_shop_catalog',$field_ext);
}
$out[$field_ext['id']]=$field_ext;
}
}
*/
$objPHPExcel->setActiveSheetIndex(1);
$objWorksheet = $objPHPExcel->getActiveSheet();
$keys = array();
$keys_flg = array('product_id' => 'id', 'categories' => 'categories', 'name' => 'name', 'quantity' => 'in_stock', 'image_name' => 'img', 'additional image names' => 'img_add', 'price' => 'price', 'date_added' => 'insert_time', 'date_modified' => 'update_time', 'viewed' => 'views', 'description' => 'html');
$out = array();
foreach ($objWorksheet->getRowIterator() as $row) {
//.........这里部分代码省略.........
示例2: reader
public function reader($filePath = null, $index = 2)
{
if ($filePath == null) {
$filePath = $_FILES['file']['tmp_name'];
}
$PHPReader = new PHPExcel_Reader_Excel2007();
if (!$PHPReader->canRead($filePath)) {
$PHPReader = new PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($filePath)) {
return 'no Excel';
}
}
$PHPExcel = $PHPReader->load($filePath);
$rows = array();
$sheet = $PHPExcel->getSheet(0);
$allColumn = $sheet->getHighestColumn();
$allRow = $sheet->getHighestRow();
$allCell = $this->AT[$allColumn];
for ($row = $index; $row <= $allRow; $row++) {
$arr = array();
for ($cell = 0; $cell <= $allCell; $cell++) {
$val = $sheet->getCellByColumnAndRow($cell, $row)->getValue();
$arr[$this->A[$cell]] = $val;
}
$rows[] = $arr;
}
return $rows;
}
示例3: updateData
function updateData($filename, $encode = 'utf-8')
{
$PHPReader = new PHPExcel_Reader_Excel2007();
if (!$PHPReader->canRead($filename)) {
$PHPReader = new PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($filename)) {
echo 'no Excel';
return;
}
}
$PHPExcel = $PHPReader->load($filename);
$currentSheet = $PHPExcel->getSheet(0);
$allColumn = $currentSheet->getHighestColumn();
$allRow = $currentSheet->getHighestRow();
$excelData = ['name' => $currentSheet->getCellByColumnAndRow(A, 1)->getValue(), 'version' => $currentSheet->getCellByColumnAndRow(A, 2)->getValue()];
$keys = [];
for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
$keys[$currentColumn] = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, 5)->getValue();
}
for ($currentRow = 6; $currentRow <= $allRow; $currentRow++) {
$tmp = [];
for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
$tmpv = $currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65, $currentRow)->getValue();
$tmp[$keys[$currentColumn]] = in_array($keys[$currentColumn], ['Id', 'Exp', 'Hp', 'Attack', 'Defense']) ? intval($tmpv) : floatval($tmpv);
}
if (!empty($tmp)) {
$excelData['list'][] = $tmp;
}
}
return $excelData;
}
示例4: index
public function index(){
//导入PHPExcel类库,因为PHPExcel没有用命名空间,只能inport导入
import("Org.Util.PHPExcel");
//要导入的xls文件,位于根目录下的Public文件夹
$filename="./Public/1.xls";
//创建PHPExcel对象,注意,不能少了\
$PHPExcel=new \PHPExcel();
//如果excel文件后缀名为.xls,导入这个类
import("Org.Util.PHPExcel.Reader.Excel5");
//如果excel文件后缀名为.xlsx,导入这下类
//import("Org.Util.PHPExcel.Reader.Excel2007");
//$PHPReader=new \PHPExcel_Reader_Excel2007();
$PHPReader=new \PHPExcel_Reader_Excel5();
//载入文件
$PHPExcel=$PHPReader->load($filename);
//获取表中的第一个工作表,如果要获取第二个,把0改为1,依次类推
$currentSheet=$PHPExcel->getSheet(0);
//获取总列数
$allColumn=$currentSheet->getHighestColumn();
//获取总行数
$allRow=$currentSheet->getHighestRow();
//循环获取表中的数据,$currentRow表示当前行,从哪行开始读取数据,索引值从0开始
for($currentRow=1;$currentRow<=$allRow;$currentRow++){
//从哪列开始,A表示第一列
for($currentColumn='A';$currentColumn<=$allColumn;$currentColumn++){
//数据坐标
$address=$currentColumn.$currentRow;
//读取到的数据,保存到数组$arr中
$arr[$currentRow][$currentColumn]=$currentSheet->getCell($address)->getValue();
}
}
dump($arr);
}
示例5: import
/**
* 导入代理商信息
* @method import
*/
public function import()
{
$file_info = R('Public/UploadExcel');
//上传excel并返回上传路径
if (!file_exists($file_info)) {
//上传失败则输出
$error_info['status'] = 0;
$error_info['info'] = $file_info;
die(json_encode($error_info));
}
import('Common.Tools.PHPExcel.PHPExcel');
$PHPExcel = new \PHPExcel();
$PHPReader = new \PHPExcel_Reader_Excel2007();
if (!$PHPReader->canRead($file_info)) {
$PHPReader = new PHPExcel_Reader_Excel5();
}
if (!$PHPReader->canRead($file_info)) {
$error_info['status'] = 0;
$error_info['info'] = '无法读取文件';
die(json_encode($error_info));
}
$PHPExcel = $PHPReader->load($file_info);
$currentSheet = $PHPExcel->getSheet(0);
$rowTotal = $currentSheet->getHighestRow();
//总行数
$columnTotal = $currentSheet->getHighestColumn();
//总列数
$columnTotal = \PHPExcel_Cell::columnIndexFromString($columnTotal);
//字母列转换为数字列
$_list = array();
for ($i = 1; $i <= $rowTotal; $i++) {
for ($j = 0; $j <= $columnTotal; $j++) {
$val = $currentSheet->getCellByColumnAndRow($j, $i)->getValue();
if (!empty($val)) {
$_list[$i - 1][] = $val;
}
}
}
foreach ($_list as $_k => $_v) {
$list[$_k]['name'] = $_v[0];
$list[$_k]['mobile'] = $_v[1];
$list[$_k]['id_card'] = $_v[2];
$list[$_k]['wechat_number'] = $_v[3];
$list[$_k]['class'] = $_v[4];
$list[$_k]['authorize_code'] = $_v[5];
$list[$_k]['ctime'] = now();
$list[$_k]['mtime'] = now();
}
$result = D('Agent')->addAll($list);
if ($result) {
$error_info['status'] = 1;
$error_info['info'] = '导入成功';
} else {
$error_info['status'] = 0;
$error_info['info'] = '导入数据失败';
}
die(json_encode($error_info));
}
示例6: createReport
public function createReport()
{
ini_set('memory_limit', '-1');
$objReader = new PHPExcel_Reader_Excel5();
$filename = 'first_data.xls';
$objPHPExcel = $objReader->load(dirname(__FILE__) . '/../../files/' . $filename);
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
echo "<pre>";
print_r($sheetData);
}
示例7: readExcel
public static function readExcel($filePath)
{
self::init();
$PHPReader = new PHPExcel_Reader_Excel2007();
if (!$PHPReader->canRead($filePath)) {
$PHPReader = new PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($filePath)) {
return null;
}
}
return $PHPReader->load($filePath);
}
示例8: exportToExcelWithHeader
/**
*
*函数名: exportToExcelWithHeader
*输入: 模板excel的路径 $filePath,例如 'C:\\123.xls'
*输入: 二维数组 要导出的内容 $dataList
* array(
* array(key1=>$value1,key2=>$value2,...),
* array(key1=>$value1,key2=>$value2,...),...
* )
*输入: 一维数组 生成excel的头部信息 $headerList
* array(数据库前台字段key1,数据库前台字段key2,...)
*输入: string $OutputFileName 输出文件名(建议输出文件名带时间戳)
*输入: $outputType 默认0输出到浏览器,输入其他保存到文件服务器并成功返回相对地址,失败返回NULL
*创建人: 石昌民
*创建时间: 2015-9-30
*/
public function exportToExcelWithHeader($filePath, $dataList, $headerList, $OutputFileName, $outputType = 0)
{
require './ThinkPHP/Library/Org/PHPExcel/PHPExcel.php';
//实例化Excel读取类
$PHPReader = new \PHPExcel_Reader_Excel2007();
$fileWebService = new FileWebController($this->userID);
if (!$PHPReader->canRead($filePath)) {
$PHPReader = new \PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($filePath)) {
return false;
}
}
//读取Excel
$PHPExcel = $PHPReader->load($filePath);
/**读取excel文件中的第一个工作表*/
$currentSheet = $PHPExcel->getSheet(0);
/**取得一共有多少行*/
$allRow = $currentSheet->getHighestRow();
$allRow++;
//实例化Excel写入类
$PHPWriter = new \PHPExcel_Writer_Excel5($PHPExcel);
//遍历数据列表中的内容,从第allRow行开始
$i = $allRow;
foreach ($dataList as $key => $value) {
$position = 'A';
foreach ($headerList as $headerKey => $headerValue) {
$currentSheet->setCellValueExplicit("{$position}" . $i, $dataList[$key][$headerValue], \PHPExcel_Cell_DataType::TYPE_STRING);
//headerKey为数据库前台字段
$position++;
}
$i++;
}
ob_end_clean();
//清除缓冲区,避免乱码
//决定是导出到浏览器还是文件服务器
if ($outputType !== 0) {
$path = Constant::WEBSERVER_EXCEL_SAVEPATH . "{$OutputFileName}.xls";
$PHPWriter->save($path);
// dump($path);
// dump(file_exists($path));
$fileURL = $fileWebService->uploadFile($path, "{$OutputFileName}.xls");
if ($fileURL == false) {
$fileURL = null;
}
return $fileURL;
return false;
} else {
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename={$OutputFileName}.xls");
header('Cache-Control: max-age=0');
$PHPWriter->save('php://output');
}
}
示例9: loadExcel
public function loadExcel($file)
{
// $PHPExcelReader = new PHPExcel_Reader_Excel2007();
// //为了可以读取所有版本Excel文件(读2007的报错)
// if(!$PHPExcelReader->canRead($file))
// {
$PHPExcelReader = new PHPExcel_Reader_Excel5();
if (!$PHPExcelReader->canRead($file)) {
return;
}
// }
$this->excelReaderObj = $PHPExcelReader->load($file);
}
示例10: xlsToCsv
function xlsToCsv($file_xls_input, $file_name_csv_output)
{
$objReader = new PHPExcel_Reader_Excel5();
try {
/** Load $inputFileName to a PHPExcel Object **/
$objPHPExcel = $objReader->load($file_xls_input);
return true;
} catch (PHPExcel_Reader_Exception $e) {
die('Error loading file: ' . $e->getMessage());
}
$writer = new PHPExcel_Writer_CSV($objPHPExcel);
$writer->save($file_name_csv_output);
}
示例11: get_rows_from_excel
public function get_rows_from_excel($filepath, &$infos)
{
if (empty($filepath)) {
return $infos;
}
$php_reader = new PHPExcel_Reader_Excel2007();
if (!$php_reader->canRead($filepath)) {
$php_reader = new PHPExcel_Reader_Excel5();
if (!$php_reader->canRead($filepath)) {
return $infos;
}
}
$cur_excel = $php_reader->load($filepath);
$cur_sheet = $cur_excel->getSheet(0);
$all_column = $cur_sheet->getHighestColumn();
//取得一共有多少列
$all_row = $cur_sheet->getHighestRow();
//取得一共有多少行
$infos_have = array();
$infos_error = array();
$i = 0;
$j = 0;
for ($cur_row = 1; $cur_row <= $all_row; $cur_row++) {
$flagadd = FALSE;
$tmprow = array();
$tmpchar = '';
for ($cur_column = 'A'; $cur_column <= $all_column; $cur_column++) {
$address = $cur_column . $cur_row;
$curinfo = trim($cur_excel->getActiveSheet()->getCell($address)->getvalue());
//if($cur_column == 'A')
//{
if (!empty($curinfo)) {
$flagadd = TRUE;
}
//}
$tmprow[] = $curinfo;
$tmpchar .= $curinfo;
}
if ($flagadd) {
$infos['infos_have'][$i] = $tmprow;
$i++;
} elseif (!empty($tmpchar)) {
$infos['infos_error'][$j] = $tmprow;
$j++;
}
}
}
示例12: excel
function excel($postdata)
{
require_once 'Excel_reader.php';
require_once 'Classes/PHPExcel.php';
$tmp = $postdata;
$save_path = "./";
//暂时上传的文件路径
$file_name = $save_path . date('Ymdhis') . ".xls";
//上传后的文件保存路径和名称
if (copy($tmp, $file_name)) {
}
$PHPExcel = new PHPExcel();
$PHPReader = new PHPExcel_Reader_Excel2007();
//为了可以读取所有版本Excel文件
if (!$PHPReader->canRead($file_name)) {
$PHPReader = new PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($file_name)) {
echo '未发现Excel文件!';
return;
}
}
//不需要读取整个Excel文件而获取所有工作表数组的函数,感觉这个函数很有用,找了半天才找到
$sheetNames = $PHPReader->listWorksheetNames($file_name);
//读取Excel文件
$PHPExcel = $PHPReader->load($file_name);
//获取工作表的数目
$sheetCount = $PHPExcel->getSheetCount();
for ($i = 0; $i < $sheetCount; $i++) {
//选择第一个工作表
$currentSheet = $PHPExcel->getSheet($i);
//取得一共有多少列
$allColumn = $currentSheet->getHighestColumn();
//取得一共有多少行
$allRow = $currentSheet->getHighestRow();
for ($currentRow = 1; $currentRow <= $allRow; $currentRow++) {
for ($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn++) {
$address = $currentColumn . $currentRow;
$data[$i][$currentRow][$currentColumn] = $currentSheet->getCell($address)->getValue();
//echo ."\t";
}
}
//$data[$i]=$currentSheet;
}
unlink($file_name);
//删除上传的文件
return $data;
}
示例13: writeCells
public function writeCells($celdas, $srcOrigen, $sheet)
{
// escribe las celdas especificas de un archivo de excel existente
if (is_string($srcOrigen)) {
$objReader = new PHPExcel_Reader_Excel5();
$objPHPExcel = $objReader->load($srcOrigen);
} else {
$objPHPExcel = $srcOrigen;
}
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
//objeto de PHPExcel, para escribir en el excel
$objPHPExcel->setActiveSheetIndex($sheet);
foreach ($celdas as $campo => $celda) {
$objPHPExcel->getActiveSheet()->setCellValue($campo, $celda);
}
return $objPHPExcel;
}
示例14: index
public function index()
{
// $xq_list = $this->manage_model->get_all_xiaoqu_list();
// foreach ($xq_list as $xq) {
// $name = str_replace("•","",$xq['name']);
// //echo $xq['id'] . ": " . $this->encode($name) . '<br>';
// $xq['jianpin'] = $this->encode($name);
// $this->manage_model->update_xiaoqu_jianpin($xq);
// }
// die('DONE');
require_once APPPATH . 'libraries/PHPExcel/PHPExcel.php';
$PHPExcel = new \PHPExcel();
$PHPReader = new \PHPExcel_Reader_Excel2007();
$file = 'E:/broker.xlsx';
//为了可以读取所有版本Excel文件
if (!$PHPReader->canRead($file)) {
$PHPReader = new \PHPExcel_Reader_Excel5();
if (!$PHPReader->canRead($file)) {
echo '未发现Excel文件!';
return;
}
}
//不需要读取整个Excel文件而获取所有工作表数组的函数,感觉这个函数很有用,找了半天才找到
$sheetNames = $PHPReader->listWorksheetNames($file);
//读取Excel文件
$PHPExcel = $PHPReader->load($file);
//获取工作表的数目
$sheetCount = $PHPExcel->getSheetCount();
//选择第一个工作表
$currentSheet = $PHPExcel->getSheet(0);
//取得一共有多少列
$allColumn = $currentSheet->getHighestColumn();
//取得一共有多少行
$allRow = $currentSheet->getHighestRow();
//循环读取数据,默认编码是utf8,这里转换成gbk输出
$data = array();
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
$name = trim($currentSheet->getCell("A" . $currentRow)->getValue());
$tel = trim($currentSheet->getCell("B" . $currentRow)->getValue());
$data[] = array('username' => $tel, 'passwd' => sha1('888888'), 'tel' => $tel, 'company_name' => "顺达地产", 'rel_name' => $name, 'region_id' => 6, 'admin_group' => 2);
}
$this->manage_model->add_broker_batch($data);
}
示例15: index
public function index()
{
set_time_limit(0);
date_default_timezone_set('Europe/Paris');
include_once ROOT_PATH . 'core/PHPExcel/PHPExcel/IOFactory.php';
$inputFileName = UPLOADS_PATH . 'example1.xls';
echo 'Loading file ', pathinfo($inputFileName, PATHINFO_BASENAME), ' using PHPExcel_Reader_Excel5<br />';
$objReader = new PHPExcel_Reader_Excel5();
// $objReader = new PHPExcel_Reader_Excel2007();
// $objReader = new PHPExcel_Reader_Excel2003XML();
// $objReader = new PHPExcel_Reader_OOCalc();
// $objReader = new PHPExcel_Reader_SYLK();
// $objReader = new PHPExcel_Reader_Gnumeric();
// $objReader = new PHPExcel_Reader_CSV();
$objPHPExcel = $objReader->load($inputFileName);
echo '<hr />';
$sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true);
$vars = array('sheet_data' => $sheetData);
$this->render('excel', $vars);
}