XmlOddTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
  3. use PhpOffice\PhpSpreadsheet\Reader\Xml;
  4. use PhpOffice\PhpSpreadsheet\Shared\File;
  5. use PHPUnit\Framework\TestCase;
  6. class XmlOddTest extends TestCase
  7. {
  8. /**
  9. * @var string
  10. */
  11. private $filename = '';
  12. protected function teardown(): void
  13. {
  14. if ($this->filename) {
  15. unlink($this->filename);
  16. $this->filename = '';
  17. }
  18. }
  19. public function testWriteThenRead(): void
  20. {
  21. $xmldata = <<< 'EOT'
  22. <?xml version="1.0" encoding="UTF-8"?><?mso-application progid="Excel.Sheet"?>
  23. <Workbook xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
  24. xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
  25. xmlns="urn:schemas-microsoft-com:office:spreadsheet"
  26. xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  27. >
  28. <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  29. <Title>Xml2003 Short Workbook</Title>
  30. </DocumentProperties>
  31. <CustomDocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  32. <my_x05d0_Int dt:dt="integer">2</my_x05d0_Int>
  33. </CustomDocumentProperties>
  34. <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  35. <WindowHeight>9000</WindowHeight>
  36. <WindowWidth>13860</WindowWidth>
  37. <WindowTopX>240</WindowTopX>
  38. <WindowTopY>75</WindowTopY>
  39. <ProtectStructure>False</ProtectStructure>
  40. <ProtectWindows>False</ProtectWindows>
  41. </ExcelWorkbook>
  42. <ss:Worksheet ss:Name="Sample Data">
  43. <Table>
  44. <Column ss:Width="96.4913"/>
  45. <Row ss:Index="8" ss:AutoFitHeight="0" ss:Height="14.9953">
  46. <Cell>
  47. <ss:Data ss:Type="String">Test String 1</ss:Data>
  48. </Cell>
  49. </Row>
  50. </Table>
  51. </ss:Worksheet>
  52. </Workbook>
  53. EOT;
  54. $this->filename = File::temporaryFilename();
  55. file_put_contents($this->filename, $xmldata);
  56. $reader = new Xml();
  57. $spreadsheet = $reader->load($this->filename);
  58. self::assertEquals(1, $spreadsheet->getSheetCount());
  59. $sheet = $spreadsheet->getActiveSheet();
  60. self::assertEquals('Sample Data', $sheet->getTitle());
  61. self::assertEquals('Test String 1', $sheet->getCell('A8')->getValue());
  62. $props = $spreadsheet->getProperties();
  63. self::assertEquals('Xml2003 Short Workbook', $props->getTitle());
  64. self::assertEquals('2', $props->getCustomPropertyValue('myאInt'));
  65. }
  66. }