IndexController.php
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use EasyWeChat\Foundation\Application;
use PHPExcel;
class IndexController extends HomeBaseController
{
/**
* 数据导入
* @param string $file excel文件
* @param string $sheet
* @return string 返回解析数据
* @throws PHPExcel_Exception
* @throws PHPExcel_Reader_Exception
*/
public function index(){
// 建立socket连接到内部推送端口
$client = stream_socket_client('tcp://127.0.0.1:5678', $errno, $errmsg, 1);
// 推送的数据,包含uid字段,表示是给这个uid推送
$data = array('uid'=>'uid1', 'percent'=>'88%','user'=>'panhaowen');
// 发送数据,注意5678端口是Text协议的端口,Text协议需要在数据末尾加上换行符
fwrite($client, json_encode($data)."\n");
// 读取推送结果
// echo fread($client, 8192);
return $this->fetch(':index');
}
public function index2(){
$url = './1111.xlsx';
//分析文件获取后缀判断是2007版本还是2003
$extend = pathinfo($url);
$extend = strtolower($extend["extension"]);
// 判断xlsx版本,如果是xlsx的就是2007版本的,否则就是2003
if ($extend == "xlsx") {
$PHPReader = new \PHPExcel_Reader_Excel2007();
$PHPExcel = $PHPReader->load($url);
} else {
$PHPReader = new \PHPExcel_Reader_Excel5();
$PHPExcel = $PHPReader->load($url);
}
$objWorksheet = $PHPExcel->getActiveSheet();
$highestRow = $objWorksheet->getHighestRow();
$highestColumn = $objWorksheet->getHighestColumn();
$highestColumnIndex = \PHPExcel_Cell::columnIndexFromString($highestColumn);//总列数
$headtitle = array();
for ($row = 1; $row <= $highestRow; $row++) {
//注意highestColumnIndex的列数索引从0开始
for ($col = 0; $col < $highestColumnIndex; $col++) {
$headtitle[$row][$col] = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
}
}
var_dump($headtitle);
}
}