审查视图

vendor/phpoffice/phpspreadsheet/samples/Basic/01_Simple.php 1.8 KB
王晓刚 authored
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
<?php

use PhpOffice\PhpSpreadsheet\Spreadsheet;

require __DIR__ . '/../Header.php';

$spreadsheet = new Spreadsheet();
$helper->log('Create new Spreadsheet object');
$spreadsheet = new Spreadsheet();

// Set document properties
$helper->log('Set document properties');
$spreadsheet->getProperties()
    ->setCreator('Maarten Balliauw')
    ->setLastModifiedBy('Maarten Balliauw')
    ->setTitle('PhpSpreadsheet Test Document')
    ->setSubject('PhpSpreadsheet Test Document')
    ->setDescription('Test document for PhpSpreadsheet, generated using PHP classes.')
    ->setKeywords('office PhpSpreadsheet php')
    ->setCategory('Test result file');

// Add some data
$helper->log('Add some data');
$spreadsheet->setActiveSheetIndex(0)
    ->setCellValue('A1', 'Hello')
    ->setCellValue('B2', 'world!')
    ->setCellValue('C1', 'Hello')
    ->setCellValue('D2', 'world!');

// Miscellaneous glyphs, UTF-8
$spreadsheet->setActiveSheetIndex(0)
    ->setCellValue('A4', 'Miscellaneous glyphs')
    ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');

$spreadsheet->getActiveSheet()
    ->setCellValue('A8', "Hello\nWorld");
$spreadsheet->getActiveSheet()
    ->getRowDimension(8)
    ->setRowHeight(-1);
$spreadsheet->getActiveSheet()
    ->getStyle('A8')
    ->getAlignment()
    ->setWrapText(true);

$value = "-ValueA\n-Value B\n-Value C";
$spreadsheet->getActiveSheet()
    ->setCellValue('A10', $value);
$spreadsheet->getActiveSheet()
    ->getRowDimension(10)
    ->setRowHeight(-1);
$spreadsheet->getActiveSheet()
    ->getStyle('A10')
    ->getAlignment()
    ->setWrapText(true);
$spreadsheet->getActiveSheet()
    ->getStyle('A10')
    ->setQuotePrefix(true);

// Rename worksheet
$helper->log('Rename worksheet');
$spreadsheet->getActiveSheet()
    ->setTitle('Simple');

// Save
$helper->write($spreadsheet, __FILE__);