1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Writer\ODS; |
6
|
|
|
|
7
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\File; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
9
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Ods as OdsWriter; |
10
|
|
|
use PHPUnit\Framework\TestCase; |
11
|
|
|
|
12
|
|
|
class AutoColorTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
private string $outputFile = ''; |
15
|
|
|
|
16
|
|
|
protected function tearDown(): void |
17
|
|
|
{ |
18
|
|
|
if ($this->outputFile !== '') { |
19
|
|
|
unlink($this->outputFile); |
20
|
|
|
$this->outputFile = ''; |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testAutoColor(): void |
25
|
|
|
{ |
26
|
|
|
// It's not clear to me what AutoColor does in Excel. |
27
|
|
|
// However, LibreOffice Dark Mode |
28
|
|
|
// can make use of a spreadsheet which uses it. |
29
|
|
|
$spreadsheet = new Spreadsheet(); |
30
|
|
|
$spreadsheet->getDefaultStyle()->getFont() |
31
|
|
|
->setAutoColor(true); |
32
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
33
|
|
|
$sheet->setCellValue('A1', 'Hello World!'); |
34
|
|
|
$sheet->setCellValue('A2', 'Hello World!'); |
35
|
|
|
$sheet->getStyle('A2')->getFont() |
36
|
|
|
->setBold(true); |
37
|
|
|
$sheet->setCellValue('A3', 'Hello World!'); |
38
|
|
|
$sheet->getStyle('A3')->getFont() |
39
|
|
|
->setItalic(true); |
40
|
|
|
$sheet->setCellValue('B1', 'Hello World!'); |
41
|
|
|
|
42
|
|
|
$writer = new OdsWriter($spreadsheet); |
43
|
|
|
$outputFile = $this->outputFile = File::temporaryFilename(); |
44
|
|
|
$writer->save($outputFile); |
45
|
|
|
$spreadsheet->disconnectWorksheets(); |
46
|
|
|
$zipfile = "zip://$outputFile#content.xml"; |
47
|
|
|
$contents = file_get_contents($zipfile); |
48
|
|
|
if ($contents === false) { |
49
|
|
|
self::fail('Unable to open file'); |
50
|
|
|
} else { |
51
|
|
|
self::assertStringContainsString('<style:text-properties style:use-window-font-color="true" fo:font-family="Calibri" fo:font-size="11.0pt"/>', $contents); |
52
|
|
|
self::assertStringContainsString('<style:text-properties fo:font-weight="bold" style:font-weight-complex="bold" style:font-weight-asian="bold" style:use-window-font-color="true" fo:font-family="Calibri" fo:font-size="11.0pt"/>', $contents); |
53
|
|
|
self::assertStringContainsString('<style:text-properties fo:font-style="italic" style:use-window-font-color="true" fo:font-family="Calibri" fo:font-size="11.0pt"/>', $contents); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|