mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-19 20:00:47 +00:00
29b07a7c86
* Namespace-Aware Code for SheetViewOptions, SheetProtection (minor break) This is fairly straightforward for SheetViewOptions. SheetProtection is a bit less straightforward. All the attributes should allow for null as well as boolean; this is especially important because Excel defaults to true for some of them and false for others (existing code always treated attributes missing from the XML as false). DocBlocks are updated to indicate the defaults. The test for isProtectionEnabled is changed to reflect this reality. Also, PhpSpreadsheet has been using true/false when writing these, but Excel uses 1/0. Because of these differences, this is a breaking change, but the consequences of the breaks should be minor. Two unit test results needed to change. Remaining areas in Reader/Xlsx which still use the namespace-unaware code include conditional formatting (internal or external), auto filters, unparsed loaded data, data validation (internal or external), alternate content, and header/footer images. * Corrections to Xls Reader and Writer New test and changed sample to go with code changes. Also doc change.
52 lines
1.9 KiB
PHP
52 lines
1.9 KiB
PHP
<?php
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
|
require __DIR__ . '/../Header.php';
|
|
|
|
// Create new Spreadsheet object
|
|
$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('Office 2007 XLSX Test Document')
|
|
->setSubject('Office 2007 XLSX Test Document')
|
|
->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')
|
|
->setKeywords('office 2007 openxml php')
|
|
->setCategory('Test result file');
|
|
|
|
// Add some data
|
|
$helper->log('Add some data');
|
|
$spreadsheet->setActiveSheetIndex(0);
|
|
$spreadsheet->getActiveSheet()->setCellValue('A1', 'Hello');
|
|
$spreadsheet->getActiveSheet()->setCellValue('B2', 'world!');
|
|
$spreadsheet->getActiveSheet()->setCellValue('C1', 'Hello');
|
|
$spreadsheet->getActiveSheet()->setCellValue('D2', 'world!');
|
|
|
|
// Rename worksheet
|
|
$helper->log('Rename worksheet');
|
|
$spreadsheet->getActiveSheet()->setTitle('Simple');
|
|
|
|
// Set document security
|
|
$helper->log('Set document security');
|
|
$spreadsheet->getSecurity()->setLockWindows(true);
|
|
$spreadsheet->getSecurity()->setLockStructure(true);
|
|
$spreadsheet->getSecurity()->setWorkbookPassword('PhpSpreadsheet');
|
|
|
|
// Set sheet security
|
|
$helper->log('Set sheet security');
|
|
$spreadsheet->getActiveSheet()->getProtection()->setPassword('PhpSpreadsheet');
|
|
// setSheet should be true in order to enable protection!
|
|
$spreadsheet->getActiveSheet()->getProtection()->setSheet(true);
|
|
// The following are set to false, i.e. user is allowed to
|
|
// sort, insert rows, or format cells without unprotecting sheet.
|
|
$spreadsheet->getActiveSheet()->getProtection()->setSort(false);
|
|
$spreadsheet->getActiveSheet()->getProtection()->setInsertRows(false);
|
|
$spreadsheet->getActiveSheet()->getProtection()->setFormatCells(false);
|
|
|
|
// Save
|
|
$helper->write($spreadsheet, __FILE__);
|