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

ods writer ignores column width #2346

Closed
black-silence opened this issue Oct 20, 2021 · 2 comments
Closed

ods writer ignores column width #2346

black-silence opened this issue Oct 20, 2021 · 2 comments

Comments

@black-silence
Copy link

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 a column width is set it should be exported and have an effect in Libreoffice.
Something like style:column-width="12.118cm" is expected in content.xml

What is the current behavior?

Custom column width and autosize have no effect, columns always have the default width in Libreoffice. content.xml contains no column width setting.

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();

$sheet = $spreadsheet->getActiveSheet();

$sheet->setCellValue('A1', 'not so long text');
$sheet->setCellValue('A2', 'longer text to test column width');
$sheet->setCellValue('B1', 0.51);
$sheet->setCellValue('B2', 100051);

$sheet->getColumnDimension('A')->setWidth(666);
#$sheet->getColumnDimension('A')->setAutoSize(true);

#$sheet->getColumnDimension('B')->setWidth(333);
$sheet->getColumnDimension('B')->setAutoSize(true);

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

Which versions of PhpSpreadsheet and PHP are affected?

phpspreadsheet 1.18.0, php 7.3.31

@msapiro
Copy link

msapiro commented Oct 27, 2021

I have the same issue. I modified the script above somewhat as follows

<?php
require 'vendor/autoload.php';

$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();

$sheet = $spreadsheet->getActiveSheet();

$sheet->setCellValue('A1', 'not so long text');
$sheet->setCellValue('A2', 'longer text to test column width');
$sheet->setCellValue('B1', 0.51);
$sheet->setCellValue('B2', 100051);

$sheet->getColumnDimension('A')->setAutoSize(true);
$sheet->getColumnDimension('B')->setAutoSize(true);

$writer1 = new \PhpOffice\PhpSpreadsheet\Writer\Ods($spreadsheet);
$writer2 = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer3 = new \PhpOffice\PhpSpreadsheet\Writer\Html($spreadsheet);

$writer1->save('test.ods');
$writer2->save('test.xlsx');
$writer3->save('test.html');

The created test.html and test.xlsx file both have the expected column widths, but test.ods has default widths.

PhpSpreadsheet 1.18.0, PHP 7.4.3

@MarkBaker
Copy link
Member

Implemented in master read for 1.23.0 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants