source: spip-zone/_squelettes_/soyezcreateurs_net/trunk/plugins/soyezcreateurs/comptetraduction_export_fonctions.php

Last change on this file was 115670, checked in by real3t@…, 9 months ago

Passage à Spout 3.0.1

File size: 869 bytes
Line 
1<?php
2
3require_once find_in_path('lib/Spout/Autoloader/autoload.php');
4       
5use Box\Spout\Writer\Common\Creator\WriterEntityFactory;
6use Box\Spout\Writer\Common\Creator\Style\StyleBuilder;
7use Box\Spout\Common\Entity\Style\Color;
8
9function trad_export_csv($trads) {
10
11        $entetes = array(
12                'ID',
13                'Nom',
14                'URL',
15                'Contenu'
16        );
17       
18        $defaultStyle = (new StyleBuilder())
19                ->setFontName('Arial')
20                ->setFontSize(11)
21                ->build();
22       
23       
24        $writer = WriterEntityFactory::createXLSXWriter(); // for XLSX files
25
26        $writer->openToBrowser('traduction.xlsx'); // stream data directly to the browser
27       
28        $writer->addRow(WriterEntityFactory::createRowFromArray($entetes, $defaultStyle)); // add a row at a time
29       
30        foreach ($trads as $trad) {
31                $writer->addRow(WriterEntityFactory::createRowFromArray($trad, $defaultStyle));
32        }
33
34        $writer->close();
35}
Note: See TracBrowser for help on using the repository browser.