Files
oleibman 0c64e18cbd Ods Reader Style Support Part 2 - Alignment, Protection, Default Fill
Continuing the work of PR #4810.

Ods Reader changes still to come
- Default border, alignment, protection
- Font
    - subscript
    - superscript
- Borders (up next)
- Style applied to entire row
- Style applied to entire column
- Parent styles?

Ods Writer changes still to come
- Default border, alignment, protections
- Style applied to entire row
- Style applied to entire column
- Parent styles?
2026-02-18 00:56:28 -08:00

63 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Writer\Ods;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Ods;
use PhpOffice\PhpSpreadsheet\Writer\Ods\Content;
use PHPUnit\Framework\TestCase;
class IndentTest extends TestCase
{
private string $compatibilityMode;
protected function setUp(): void
{
$this->compatibilityMode = Functions::getCompatibilityMode();
Functions::setCompatibilityMode(
Functions::COMPATIBILITY_OPENOFFICE
);
}
protected function tearDown(): void
{
parent::tearDown();
Functions::setCompatibilityMode($this->compatibilityMode);
}
public function testWriteSpreadsheet(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'aa');
$sheet->setCellValue('B1', 'bb');
$sheet->setCellValue('A2', 'cc');
$sheet->setCellValue('B2', 'dd');
$sheet->getStyle('A1')->getAlignment()->setIndent(2);
$writer = new Ods($spreadsheet);
$content = new Content($writer);
$xml = $content->write();
self::assertStringContainsString(
'<style:style style:name="ce0" style:family="table-cell" style:parent-style-name="Default">'
. '<style:table-cell-properties style:vertical-align="bottom" style:rotation-angle="0" style:rotation-align="none" fo:background-color="transparent"/>'
. '<style:text-properties fo:color="#000000" fo:font-family="Calibri" fo:font-size="11pt"/>'
. '</style:style>',
$xml
);
self::assertStringContainsString(
'<style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default">'
. '<style:table-cell-properties style:vertical-align="bottom" style:rotation-angle="0" style:rotation-align="none" fo:background-color="transparent"/>'
. '<style:paragraph-properties fo:margin-left="0.2086in"/>' // fo:margin-left is what we're looking for
. '<style:text-properties fo:color="#000000" fo:font-family="Calibri" fo:font-size="11pt"/>'
. '</style:style>',
$xml
);
self::assertSame(3, substr_count($xml, 'table:style-name="ce0"'));
self::assertSame(1, substr_count($xml, 'table:style-name="ce1"'));
$spreadsheet->disconnectWorksheets();
}
}