-
Notifications
You must be signed in to change notification settings - Fork 0
/
criar_simples.php
37 lines (27 loc) · 976 Bytes
/
criar_simples.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
<?php
// Autoload do Composer
require __DIR__ . '/vendor/autoload.php';
// Dependências do Projeto
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
// Instância Principal da Planilha
$spreadsheet = new Spreadsheet();
// Obtém a Aba Ativa Dentro do Arquivo Excel
$sheet = $spreadsheet->getActiveSheet();
// Define o Conteúdo da Célula A1 (Título do Arquivo)
$sheet->setCellValue('A1', 'XLSX com PHP');
// Cabeçalhos
$sheet->setCellValue('A3', 'ID');
$sheet->setCellValue('B3', 'Nome');
$sheet->setCellValue('C3', 'Valor');
// Valores - Primeira Linha
$sheet->setCellValue('A4', '1');
$sheet->setCellValue('B4', 'Monitor');
$sheet->setCellValue('C4', '600.00');
// Valores - Segunda Linha
$sheet->setCellValue('A5', '2');
$sheet->setCellValue('B5', 'Impressora');
$sheet->setCellValue('C5', '900.00');
// Escreve o Arquivo no Disco com o Formato XLSX
$writer = new Xlsx($spreadsheet);
$writer->save('./arquivos/arquivo.xlsx');