diff --git a/src/Spout/Writer/Common/Entity/Worksheet.php b/src/Spout/Writer/Common/Entity/Worksheet.php index 1a3e1af..ffdd1d2 100644 --- a/src/Spout/Writer/Common/Entity/Worksheet.php +++ b/src/Spout/Writer/Common/Entity/Worksheet.php @@ -141,15 +141,13 @@ class Worksheet */ public function autoSetWidth($cell, $style, $zeroBasedIndex) { - $size = strlen($cell->getValue()) ?? 1;//use 1 as length if cell empty - $size *= (float)($style->getFontSize() ?? 10); + $size = 1 + strlen($cell->getValue());//ensure we have at least 1 space $size *= $style->isFontBold() ? 1.2 : 1.0; if ($this->getWidthCalculation() == Worksheet::W_FIXED) { $total = array_sum($this->getColumnWidths()); $total = $total ?: $size; $size = ($size / $total) * $this->getFixedSheetWidth(); } - $size /= 10; $this->setMaxColumnWidth($zeroBasedIndex, $size); } diff --git a/src/Spout/Writer/ODS/Manager/WorksheetManager.php b/src/Spout/Writer/ODS/Manager/WorksheetManager.php index 3d10d79..388a747 100644 --- a/src/Spout/Writer/ODS/Manager/WorksheetManager.php +++ b/src/Spout/Writer/ODS/Manager/WorksheetManager.php @@ -286,6 +286,7 @@ class WorksheetManager implements WorksheetManagerInterface $widths = $worksheet->getColumnWidths(); //todo: this may not be adequate for multiple worksheets foreach ($widths as $i => $width){ + //this is a rough equivalent based on pixel density $win = round($width / 9.6, 2);//convert to inches $colNo = $i + 1; $style .= '