mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-27 17:11:13 +00:00
482fe6de64
* Recognize 'Hidden' Attribute in Xml Spreadsheet Fix #3566; PhpSpreadsheet should now handle Hidden attribute for rows and columns in Xml spreadsheets. Also added the ability to load Xml spreadsheet from string rather than file, as can be done for Csv and Html. * Add Support for Top Left Cell Another missing piece. * Font Bold/Italic Was always setting to true rather than checking value for 0/1. * Active Sheet Index Had always been set to hard-coded 0. Read it from XML if available. * Selected Cells Get Selected Cells from XML when available. * Worksheet Protection and Style Protection Add support for those to Xml Reader. * Column Spans Not really an essential part of Excel, used in Xml to reduce file size.
63 lines
2.9 KiB
PHP
63 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Xml;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class XmlProtectionTest extends TestCase
|
|
{
|
|
public function testProtection(): void
|
|
{
|
|
$xmldata = <<< 'EOT'
|
|
<?xml version="1.0"?>
|
|
<?mso-application progid="Excel.Sheet"?>
|
|
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
|
|
<Styles>
|
|
<Style ss:ID="Default" ss:Name="Normal">
|
|
<Protection x:HideFormula="1" ss:Protected="1"/>
|
|
</Style>
|
|
<Style ss:ID="visible">
|
|
<Protection x:HideFormula="0" ss:Protected="1"/>
|
|
</Style>
|
|
<Style ss:ID="writable">
|
|
<Protection x:HideFormula="1" ss:Protected="0"/>
|
|
</Style>
|
|
<Style ss:ID="neither">
|
|
</Style>
|
|
</Styles>
|
|
<Worksheet ss:Name="sheet 1" ss:Protected="1">
|
|
<ss:Table>
|
|
<ss:Row>
|
|
<ss:Cell ss:Formula="=1">
|
|
<ss:Data ss:Type="Number"/>
|
|
</ss:Cell>
|
|
<ss:Cell ss:StyleID="visible" ss:Formula="=2">
|
|
<ss:Data ss:Type="Number"/>
|
|
</ss:Cell>
|
|
<ss:Cell ss:StyleID="writable" ss:Formula="=3">
|
|
<ss:Data ss:Type="Number"/>
|
|
</ss:Cell>
|
|
</ss:Row>
|
|
</ss:Table>
|
|
</Worksheet>
|
|
</Workbook>
|
|
EOT;
|
|
$reader = new Xml();
|
|
$spreadsheet = $reader->loadSpreadsheetFromString($xmldata);
|
|
self::assertEquals(1, $spreadsheet->getSheetCount());
|
|
|
|
$sheet = $spreadsheet->getActiveSheet();
|
|
self::assertEquals('sheet 1', $sheet->getTitle());
|
|
self::assertTrue($sheet->getProtection()->isProtectionEnabled());
|
|
self::assertSame('protected', $sheet->getCell('A1')->getStyle()->getProtection()->getLocked());
|
|
self::assertSame('protected', $sheet->getCell('A1')->getStyle()->getProtection()->getHidden());
|
|
self::assertSame('protected', $sheet->getCell('B1')->getStyle()->getProtection()->getLocked());
|
|
self::assertSame('unprotected', $sheet->getCell('B1')->getStyle()->getProtection()->getHidden());
|
|
self::assertSame('unprotected', $sheet->getCell('C1')->getStyle()->getProtection()->getLocked());
|
|
self::assertSame('protected', $sheet->getCell('C1')->getStyle()->getProtection()->getHidden());
|
|
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
}
|