Novis\Spreadsheet\Reader::properties
$reader->properties(): PropertiesReturns the document properties of the workbook: the information Excel shows under File, Info.
The result has title, subject, author, company and keywords, each a tainted string or null, and created, the time the file was created, as a Core\Time\Instant or null. An Instant is one moment with no time zone. Call in with a zone to get the local date and time.
Good to know: a property the file does not have is null. Every property of a CSV file is null, because a CSV file is only text. For an ods file, author is the person who created the file. The text comes from the file, so check it before you show it on a web page.
The examples below read the title and the author, show the time a file was created in a time zone, and read the properties of a CSV file.
Return value
Returns Properties.
Examples
Read the title and the author
<?nvs// Shows how to read the title, the author and the other properties of a workbook.use Novis\Spreadsheet\Reader;use Novis\Spreadsheet\Workbook;
var $book = Workbook::createInMemory({ properties: { title: 'Price list', author: 'Shop', company: 'Shop Ltd', keywords: 'prices, 2024' } });$book->addSheet('Prices')->addRow(['Item', 'Price']);var $reader = Reader::open($book->finish()->bytes ?? Core\Bytes::fill(0, 0));
// A property the file does not have is `null`. This file has no subject.var $properties = $reader->properties();echo 'title: ', $properties->title ?? 'null', "\n";echo 'author: ', $properties->author ?? 'null', "\n";echo 'company: ', $properties->company ?? 'null', "\n";echo 'keywords: ', $properties->keywords ?? 'null', "\n";echo 'subject: ', $properties->subject ?? 'null', "\n";title: Price listauthor: Shopcompany: Shop Ltdkeywords: prices, 2024subject: nullThe time a file was created
<?nvs// Shows how to read the time a workbook was created and show it in a time zone.use Novis\Spreadsheet\Reader;use Novis\Spreadsheet\Workbook;
var $made = Core\Time\DateTime::parse('2024-03-01 09:30', 'yyyy-MM-dd HH:mm', 'UTC')->toInstant();var $book = Workbook::createInMemory({ properties: { created: $made } });$book->addSheet('Orders')->addRow(['Order']);var $reader = Reader::open($book->finish()->bytes ?? Core\Bytes::fill(0, 0));
// `created` is an `Instant`, one moment with no time zone. `in` gives the local time of a zone.var $created = $reader->properties()->created;if ($created != null) { echo 'created: ', $created->toIso(), "\n"; echo 'in Berlin: ', $created->in('Europe/Berlin')->format('yyyy-MM-dd HH:mm'), "\n";}created: 2024-03-01T09:30:00Zin Berlin: 2024-03-01 10:30A csv file has no properties
<?nvs// Shows that every property of a CSV file is `null`.use Novis\Spreadsheet\Reader;
// A CSV file is only text, so it has no title and no author.var $properties = Reader::open("Item,Price\nWidget,2.50\n" as bytes)->properties();echo 'title: ', $properties->title ?? 'null', "\n";echo 'author: ', $properties->author ?? 'null', "\n";echo 'created: ', $properties->created == null ? 'null' : 'set', "\n";title: nullauthor: nullcreated: null