2016-08-31 16:15:54 +00:00
< ? php
2017-05-17 22:02:17 +00:00
use PhpOffice\PhpSpreadsheet\Document\Properties ;
use PhpOffice\PhpSpreadsheet\IOFactory ;
2017-10-01 08:48:59 +00:00
require __DIR__ . '/../Header.php' ;
2016-08-31 16:15:54 +00:00
2016-10-06 11:49:41 +00:00
$inputFileType = 'Xls' ;
2017-10-01 08:48:59 +00:00
$inputFileName = __DIR__ . '/../templates/31docproperties.xls' ;
2016-08-31 16:15:54 +00:00
2017-05-17 22:02:17 +00:00
$spreadsheetReader = IOFactory :: createReader ( $inputFileType );
2016-08-31 16:15:54 +00:00
$callStartTime = microtime ( true );
$spreadsheet = $spreadsheetReader -> load ( $inputFileName );
$helper -> logRead ( $inputFileType , $inputFileName , $callStartTime );
$helper -> log ( 'Adjust properties' );
$spreadsheet -> getProperties () -> setTitle ( 'Office 95 XLS Test Document' )
2018-01-28 06:59:38 +00:00
-> setSubject ( 'Office 95 XLS Test Document' )
-> setDescription ( 'Test XLS document, generated using PhpSpreadsheet' )
-> setKeywords ( 'office 95 biff php' );
2016-08-31 16:15:54 +00:00
// Save Excel 95 file
$filename = $helper -> getFilename ( __FILE__ , 'xls' );
2017-05-17 22:02:17 +00:00
$writer = IOFactory :: createWriter ( $spreadsheet , 'Xls' );
2016-08-31 16:15:54 +00:00
$callStartTime = microtime ( true );
$writer -> save ( $filename );
$helper -> logWrite ( $writer , $filename , $callStartTime );
$helper -> logEndingNotes ();
// Reread File
2016-10-06 11:49:41 +00:00
$helper -> log ( 'Reread Xls file' );
2017-05-17 22:02:17 +00:00
$spreadsheetRead = IOFactory :: load ( $filename );
2016-08-31 16:15:54 +00:00
// Set properties
$helper -> log ( 'Get properties' );
$helper -> log ( 'Core Properties:' );
$helper -> log ( ' Created by - ' . $spreadsheet -> getProperties () -> getCreator ());
2017-10-01 08:48:59 +00:00
$helper -> log ( ' Created on - ' . date ( 'd-M-Y' . $spreadsheet -> getProperties () -> getCreated ()) . ' at ' . date ( 'H:i:s' . $spreadsheet -> getProperties () -> getCreated ()));
2016-08-31 16:15:54 +00:00
$helper -> log ( ' Last Modified by - ' . $spreadsheet -> getProperties () -> getLastModifiedBy ());
2017-10-01 08:48:59 +00:00
$helper -> log ( ' Last Modified on - ' . date ( 'd-M-Y' . $spreadsheet -> getProperties () -> getModified ()) . ' at ' . date ( 'H:i:s' . $spreadsheet -> getProperties () -> getModified ()));
2016-08-31 16:15:54 +00:00
$helper -> log ( ' Title - ' . $spreadsheet -> getProperties () -> getTitle ());
$helper -> log ( ' Subject - ' . $spreadsheet -> getProperties () -> getSubject ());
$helper -> log ( ' Description - ' . $spreadsheet -> getProperties () -> getDescription ());
$helper -> log ( ' Keywords: - ' . $spreadsheet -> getProperties () -> getKeywords ());
$helper -> log ( 'Extended (Application) Properties:' );
$helper -> log ( ' Category - ' . $spreadsheet -> getProperties () -> getCategory ());
$helper -> log ( ' Company - ' . $spreadsheet -> getProperties () -> getCompany ());
$helper -> log ( ' Manager - ' . $spreadsheet -> getProperties () -> getManager ());
$helper -> log ( 'Custom Properties:' );
$customProperties = $spreadsheet -> getProperties () -> getCustomProperties ();
foreach ( $customProperties as $customProperty ) {
$propertyValue = $spreadsheet -> getProperties () -> getCustomPropertyValue ( $customProperty );
$propertyType = $spreadsheet -> getProperties () -> getCustomPropertyType ( $customProperty );
2017-05-17 22:02:17 +00:00
if ( $propertyType == Properties :: PROPERTY_TYPE_DATE ) {
2016-08-31 16:15:54 +00:00
$formattedValue = date ( 'd-M-Y H:i:s' , $propertyValue );
2017-05-17 22:02:17 +00:00
} elseif ( $propertyType == Properties :: PROPERTY_TYPE_BOOLEAN ) {
2016-08-31 16:15:54 +00:00
$formattedValue = $propertyValue ? 'TRUE' : 'FALSE' ;
} else {
$formattedValue = $propertyValue ;
}
$helper -> log ( ' ' . $customProperty . ' - (' . $propertyType . ') - ' . $formattedValue );
}
$helper -> logEndingNotes ();