-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimportar_indicador.php
83 lines (59 loc) · 1.99 KB
/
importar_indicador.php
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
79
80
81
82
83
<?php include "header.php"; ?>
<body>
<?php include "menu/me_admin.php"; ?>
<main class="col-sm-9 offset-sm-3 col-md-10 offset-md-2 pt-3">
<h1>Importar inscrições</h1>
<div>
<br />
<?php
@ini_set('display_errors', '1');
error_reporting(E_ALL);
set_time_limit(0);
$antes = strtotime(date('Y-m-d H:i:s')); // note que usei hífen
require_once dirname(__FILE__) . '/classes/PHPExcel.php';
if(isset($_GET['file'])){
$fileName = $_GET['file'];
/** detecta automaticamente o tipo de arruivo que será carregado */
$excelReader = PHPExcel_IOFactory::createReaderForFile($fileName);
//Se não precisarmos de formatação
$excelReader->setReadDataOnly();
//carregar apenas algumas abas
//$loadSheets = array('aba1', 'aba2');
//$excelReader->setLoadSheetsOnly($loadSheets);
//o comportamente padrão é carregar todas as abas
$excelReader->setLoadAllSheets();
$excelObj = $excelReader->load($fileName);
//$excelObj->getActiveSheet()->toArray(null, true,true,true);
$sheet = $excelObj->getSheet(0);
$highestRow = $sheet->getHighestRow();
$highestColumn = $sheet->getHighestColumn();
echo "Linhas: ".$highestRow;
$matriz = array();
// Loop through each row of the worksheet in turn
for ($row = 1; $row <= $highestRow; $row++){
// Read a row of data into an array
$rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row,
NULL,
TRUE,
FALSE);
// Gera os índices
if($row == 1){
$indice = $rowData[0];
}else{
for($k = 0; $k < count($rowData[0]); $k++){
$matriz[$row][$indice[$k]] = $rowData[0][$k];
}
}
echo "<pre>";
var_dump($matriz);
echo "</pre>";
}
$depois = strtotime(date('Y-m-d H:i:s'));
$tempo = $depois - $antes;
echo "<br /><br /> Importação executada em $tempo segundos";
}
?>
</div>
<?php
include "footer.php";
?>