Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OdsWriter does not include indent formatting #4261

Closed
1 of 8 tasks
MARSMemory opened this issue Dec 3, 2024 · 0 comments · Fixed by #4263
Closed
1 of 8 tasks

OdsWriter does not include indent formatting #4261

MARSMemory opened this issue Dec 3, 2024 · 0 comments · Fixed by #4263

Comments

@MARSMemory
Copy link

MARSMemory commented Dec 3, 2024

This is:

- [X] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

When saving as .ods, indent formatting on a cell is applied.

What is the current behavior?

Indent formatting is lost when saved as .ods. (Other formatting seems fine.)

What are the steps to reproduce?

Please provide a Minimal, Complete, and Verifiable example of code that exhibits the issue without relying on an external Excel file or a web server:

<?php

require __DIR__ . '/vendor/autoload.php';

// Create new Spreadsheet object
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();

$worksheet->setCellValue('A1', 'Test text');
$worksheet->getStyle('A1')->getAlignment()->setIndent(2);

$writer = new \PhpOffice\PhpSpreadsheet\Writer\Ods($spreadsheet);
$writer->save('indent.ods');

If this is an issue with reading a specific spreadsheet file, then it may be appropriate to provide a sample file that demonstrates the problem; but please keep it as small as possible, and sanitize any confidential information before uploading.

What features do you think are causing the issue

  • Reader
  • Writer
  • Styles
  • Data Validations
  • Formula Calculations
  • Charts
  • AutoFilter
  • Form Elements

Does an issue affect all spreadsheet file formats? If not, which formats are affected?

It affects .ods. Saving as .xlsx does apply the indent. Other formats were not tested.

Which versions of PhpSpreadsheet and PHP are affected?

PHP 8.1.2
PhpSpreadsheet 3.5.0

oleibman added a commit to oleibman/PhpSpreadsheet that referenced this issue Dec 6, 2024
Fix PHPOffice#4261. Ods does nothing with the `indent` property of Alignment. The fix is easy, but not as easy as it should be. Excel treats indent as an int in some unspecified unit. Ods, on the other hand, specifies it as a float with unit (inches, ems, etc.). Since MS does not reveal what an indent unit is, I resorted to some experimentation. It appears that 1 unit is equal to  0.1043 inches. That is not a guaranteed relationship - the conversion might be non-linear, or it might be affected by external factors like font size. I think multiplying by 0.1043 is adequate for now, and unquestionably better than what we're currently doing (ignoring the property). If it breaks down at some point, we'll look at it again. BTW, Shared\Drawing uses some conversion values of 9525, which, reciprocating and sliding the decimal point along yields a value of 0.10498..., which is close but not close enough for me to use.

The other property used in conjunction with indent is `text-align`, and here we have not been doing the right thing. If that property has the default value (`General`), it is treated as `start` (i.e. `left` on LTR docs and presumably `right` on RTL). This will align numbers as if they were text, which does no harm (they're still usable as numbers), but is not how LibreOffice handles them by default. Ods writer is changed to omit `text-align` when it is set to `General`, and let LibreOffice choose the appropriate alignment.

These changes are for Writer only. Ods Reader support for styles remains severely lacking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant