https://bugs.freedesktop.org/show_bug.cgi?id=57150

--- Comment #6 from Daniel Lopez <[email protected]> ---
I've been trying to determine the logic behind the existing optimal column
width calculation by experimenting. It seems that it boils down to considering
the non-blank cells in the column, and whether they are non-wrapped or wrapped
(via Format Cells -> Alignment -> Wrap text automatically).

If there are any non-wrapped cells in the column then the optimal width is
calculated as the widest of those. Any wrapped cells are ignored in this case.
It only takes one non-wrapped (and non-blank) cell to exist, to trigger this
mode.

For example in the spreadsheet attached above, most of the cells in the first
column are wrapped, except for A20 which only has two letters in it (sorry, I
can't type Russian) and is not wrapped, so this cell alone causes the optimal
width to be so narrow.

(Well actually, A1 is also non-wrapped and wider than A20 but it doesn't seem
to be affecting the result, which is because it is merged. I haven't
investigate merged cells much but it seems like they are simply ignored in all
cases whether wrapped or not.)

If there are no non-wrapped cells in the column, then the optimal column width
is calculated as the default column width. I'm not sure where you set this in
LibreOffice (I had a quick Google and found something about templates?) but
it's the same width as if you select Format -> Column -> Width and then tick
the box for "Default value", which in my case currently happens to be 2.26cm.
So, the wrapped cells are ignored in this case too. To be clear, the widths of
wrapped cells are never considered in the optimal column width calculation.
(Just realised that while typing this out.)

Now, here's how I think Excel does it (from memory), which I always thought was
useful and I wouldn't mind if LibreOffice copied its behaviour on this point.

All non-blank cells in the column are considered. If a cell is non-wrapped, its
"optimal width" (ie. just of that cell, not the whole column yet) is the width
of the content. If a cell is wrapped, then there are two cases in working out
the cell's "optimal width" which, interestingly, brings the current column
width into consideration as well as the cell's contents:

If the current column width is so narrow that the longest word in the cell
cannot fit completely, then the cell's optimal width is the width of that
longest word. Else, if the current column width is wider than the longest word,
then the cell's optimal width is the current column width reduced as much as
possible while not changing the existing word wrapping of the cell.

(This way in which Excel considers the current column width in order to change
it as little as possible was always handy to me in giving the program a 'hint'
that it could take up a bit more space rather than make the column as narrow as
technically possible; firstly by resizing the column roughly to the width I
would like, then double-clicking to 'trim' the right edge to be neat and tidy.)

Finally, after calculating the "optimal width" for every non-blank cell in the
column, the optimal width for the column itself is the maximum of all those.

I don't know from memory how Excel deals with merged cells, but feel like
that's getting to the stage of asking too much of the program to make sense of
your spreadsheet and am happy with the optimal width algorithm just ignoring
them. I would love it if LibreOffice implemented the Excel behaviour as far as
described above, though, as I used to tidy totally messed up sheets (typically
received from coworkers) very quickly with that!

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs

Reply via email to