-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamplesFile.php
More file actions
86 lines (75 loc) · 2.73 KB
/
samplesFile.php
File metadata and controls
86 lines (75 loc) · 2.73 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
79
80
81
82
83
84
85
86
<?php
class samplesFile {
private $fOrigem;
public function __construct($arq = false) {
if ($arq) {
$this->openFile($arq);
return true;
}
else {
return false;
}
}
public function __destruct() {
$this->closeFile();
return true;
}
public function openFile($arq){
$this->fOrigem = fopen($arq,'r');
$arq2 = explode('.',$arq);
$arq2 = 'tab_' . $arq2[0] . '.csv';
$this->arqSaida = $arq2;
}
public function closeFile() {
fclose($this->fOrigem);
return true;
}
public function getValues($table,$col) {
if ($this->fOrigem){
$i = 1;
$this->header[] = 'Element'; // nomes das colunas
while (($buffer = fgets($this->fOrigem))) {
if (strpos($buffer, 'Comment')) { // achou cabecalho da coluna
$buffer = trim(preg_replace('/( )+/', ' ', $buffer));
$dados = explode(':',$buffer); // divide a linha
$this->header[] = $dados[2];
continue;
}
if (strpos($buffer, $table)){ // está na tabela alvo
while (($buffer = fgets($this->fOrigem))) {
$buffer = trim(preg_replace('/( )+/', ' ', $buffer));
if ((empty($buffer)) or (substr_count($buffer, "---------")>0)) continue; //linha vazia
$dados = explode(' ',$buffer); // divide a linha
$value = $dados[$col-1]; // obtem valor
$element = $dados[0];
$this->tabulado[$element][$i] = $value;
if (strpos($buffer, 'otal')){ // está na última linha da tabela
break;
}
}
}
else continue;
$i++;
}
}
return true;
}
public function putCSV(){
$this->table = '';
$row = implode(";", $this->header) . "\n";
$this->table.= $row;
foreach ($this->tabulado as $element=>$values){
$row = "$element;" . implode(";", $values) . "\n";
$this->table.=$row;
}
return true;
}
public function download(){
header("Content-type: application/vnd.ms-excel");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename={$this->arqSaida}");
header("Pragma: no-cache");
echo $this->table;
return true;
}
}