D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
rosario
/
adm
/
app
/
gre
/
Views
/
Cotacao
/
Filename :
VieCtRepresMarcaExcel.php
back
Copy
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); ob_start(); $path = getcwd(); //VAR_DUMP(URLFPDF); $Dados = $_GET; $Lanc = new \App\gre\Models\Cotacao\ModCtRepresMarcaListar(); $arr = $Lanc->listarRepresMarca($Dados); $repres_nome = $arr[0]['apelido']; $nome_fantasia = $arr[0]['nome_fantasia']; $repres_id = $arr[0]['repres_id']; $cabec = "ROSÁRIO - MARCAS ATENDIDAS ". $nome_fantasia. ' - '.$repres_nome; $nomePlanilha = "MARCAS ATENDIDAS_".$repres_id.'_'.$repres_nome; require $_SERVER['DOCUMENT_ROOT']."/rosario/adm/vendor/autoload.php"; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use PHPOffice\phpspreadsheet\Shared\Date; //include_once("conecta.php"); $styleArray = [ 'borders' => [ 'allBorders' => [ 'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN, 'color' => ['argb' => '00000000'], ], ], ]; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); //$spreadsheet->getActiveSheet()->setPrintGridlines(true); $spreadsheet->getActiveSheet()->getStyle('A1:B2') ->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); $sheet->getColumnDimension('A')->setWidth(140,'px'); $sheet->getColumnDimension('B')->setWidth(200,'px'); $spreadsheet->getActiveSheet()->mergeCells('A1:B1'); $sheet->getStyle('A1')->getFont()->setBold(true); $sheet->getStyle('A2:B2')->getFont()->setBold(true); $sheet->setCellValue('A1', $cabec); $sheet->setCellValue('A2', 'Cod.Marca'); $sheet->setCellValue('B2', 'Marca'); $i = 3; foreach ($arr as $lactos) { extract($lactos); $sheet->setCellValue('A'.$i, $marca_id); $sheet->setCellValue('B'.$i, $nome); $i = $i + 1; } $sheet->getStyle('A1:B'.$i)->applyFromArray($styleArray); //$sheet->setCellValue('A1', 'Hello World !'); //var_dump($sheet); $writer = new Xlsx($spreadsheet); $writer->save($nomePlanilha.'.xlsx'); $fileName = $nomePlanilha.'.zip'; //$path = '/var/www/html/rosario/adm/'; //__DIR__ ; $path = 'C:/wamp64/www/rosario/adm/'; //__DIR__ ; $fullPath = $path.$fileName; $diretorio = dir($path); $nomeArquivo = $nomePlanilha.'.xlsx'; //var_dump('fullpath:'. $fullPath); $zip = new \ZipArchive(); if( $zip->open($fullPath, \ZipArchive::CREATE) ){ while($arquivo = $diretorio->read()){ var_dump('$arquivo=> '.$arquivo.'<br>'); var_dump('$nomearquivo=> '.$nomeArquivo.'<br>'); $extensao = substr($arquivo,strlen($arquivo)-4,4); if($arquivo == $nomeArquivo ){ // var_dump('arquivo - planilha=> '.$arquivo.' - '. $nomeplanilha.'<br>'); //var_dump('path e arquivo=>'. $arquivo); $zip->addFile($path.'/'.$arquivo, $arquivo); //var_dump('zipou'); } } $zip->close(); } if(file_exists($fullPath)){ // var_dump('achou para subir'); // Forçamos o donwload do arquivo. header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="'.$fileName.'"'); readfile($fullPath); $path = '/var/www/html/rosario/adm/'; //__DIR__ ; $fileDelz =$nomePlanilha.'.zip'; $fullPathDelz = $path.'/'.$fileDelz; $fileDelx = $nomePlanilha.'.xlsx'; $fullPathDelx = $path.'/'.$fileDelx; $diretorio = dir($path); unlink($fileName); unlink($fullPathDelx); } die;