You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 26, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on May 26, 2022. It is now read-only.
Instead of using the default width/height, Spout could calculate the optimal width/height for each cell, based on its content.
This involves using a graphics library, render the text content with the chosen font and get the width/height of the rendered text.
This calculation may be slow so it should be optional. It can also be used when using "wrap text" as wrapping does not work well without a custom row height in LibreOffice.
Spout should expose an option to automatically set the optimal width/height but should also allow developers to specify a max width / height. When the max width is reached, the content will automatically wrap and the cell height will increase. It will increase until it reaches the max height.
Reacted by Rauan Mayemir, Hocdoc, Alexey Salnikov, Harry Gulliford, gmmarc, Jérôme Bogaerts, Esteban De la Rosa, Richard Thornton, Ivan Pshenitsyn, vuducmanh96vp and 29 more
Oh, figured it out--just added this line to Worksheet.php, startSheet(), between the header and the data: fwrite($this->sheetFilePointer, '<cols><col min="1" max="1" width="100" customWidth="1"/><col min="2" max="6" width="30" customWidth="1"/></cols>');
Reacted by David Beveridge, Deepak, Paul Ntabuye Butera, vuducmanh96vp, jankulma, warlaft, Marcelo F F Martins, Nahirnyi, stonez56, meguai and 6 more
@jordanade You can also look at #225 if you need to hack something that works.
I'm not a big fan of this as it creates an API that is specific to XLSX. Also, if Spout could automatically calculate the width of each column, it would solve 95% of the problems. So I'd rather have this transparent solution in place, instead of having to manually specify the width of each column.
Hi there, have you been able to come up with a solution for the autosizing of column widths and row heights already?
If not, I've come with an intermediary solution, which - while less accurate than imagettfbbox - is IMHO a decent tradeoff between performance and accuracy.
On average it increases the runtime by about 50%-100% and the widths are on average about 1 character off (usually too wide).
It's a bit hacky though (requires serious refinement! =) and involves a csv that holds base sizes for each font and character in the ASCII range, which is why I'm hesitating to fork->code->pull spout, since I dont know if it's a viable solution to integrate that into spout.
@nimmneun Nobody started working on this enhancement. If you already built something, feel free to share it. Either share a link to your commit or create a pull request.
It's always good to get inspiration from others :)
@adrilo I understand you're busy but this is a super useful feature. I've read the guide to contributing and I'm willing to work on this. Do you have any pointers to what has already been tried or your recommendations? I also noticed it's now possible to write cells in v3, this makes the issue of cell merging easier from a technical angle. I can create PRs for both but would love to get pointers so I don't duplicate someone's work.
@xwiz This specific issue is about the automation of the calculation. What's very difficult about this is the fact that you can only determine the width of the column after the last row is written. Which means for each new row, you need to compute the width of each cell and keep the max width. Before closing the writer, the info about the max width needs to be added to the right XML file. Computing the width of a cell may be computationally intensive, especially since Spout supports different fonts (the width of a given text differs from font to font).
Also, we're trying to keep the same features for all file formats (usually XLSX and ODS). So if you're interested to work on that, please remember that. Thanks!
Hi, just like ODS already did it, with openspout/openspout#45 now also XLSX writes the rows in a temporary file and only after that it writes all the remaining data, thanks to the speed of stream_copy_to_stream.
So now column with, alongside auto-sizing, could be easily supported and already achievable by user code 🚀
Activity
zendre4 commentedon Feb 25, 2016
+1
linaspasv commentedon Mar 2, 2016
+1
ttkulm commentedon Apr 20, 2016
+1 Would be a really good feature!
arisdario commentedon Apr 27, 2016
+10
jordanade commentedon May 25, 2016
I don't need auto-fit, just a way to set widths for each column! Any way to workaround/hack this for now?
jordanade commentedon May 25, 2016
Oh, figured it out--just added this line to Worksheet.php, startSheet(), between the header and the data:
fwrite($this->sheetFilePointer, '<cols><col min="1" max="1" width="100" customWidth="1"/><col min="2" max="6" width="30" customWidth="1"/></cols>');adrilo commentedon May 26, 2016
@jordanade You can also look at #225 if you need to hack something that works.
I'm not a big fan of this as it creates an API that is specific to XLSX. Also, if Spout could automatically calculate the width of each column, it would solve 95% of the problems. So I'd rather have this transparent solution in place, instead of having to manually specify the width of each column.
jordanade commentedon Jun 9, 2016
Surely there is room for APIs that may not work for all possible file outputs? Best effort, etc...
adrilo commentedon Jun 15, 2016
I'm actually trying to avoid this as much as possible. Although I'll definitely reconsider after implementing the automated method.
nimmneun commentedon Aug 29, 2016
Hi there, have you been able to come up with a solution for the autosizing of column widths and row heights already?
If not, I've come with an intermediary solution, which - while less accurate than imagettfbbox - is IMHO a decent tradeoff between performance and accuracy.
On average it increases the runtime by about 50%-100% and the widths are on average about 1 character off (usually too wide).
It's a bit hacky though (requires serious refinement! =) and involves a csv that holds base sizes for each font and character in the ASCII range, which is why I'm hesitating to fork->code->pull spout, since I dont know if it's a viable solution to integrate that into spout.
adrilo commentedon Aug 30, 2016
@nimmneun Nobody started working on this enhancement. If you already built something, feel free to share it. Either share a link to your commit or create a pull request.
It's always good to get inspiration from others :)
36 remaining items
jeanvcastro commentedon Sep 10, 2020
+1
smartniazi commentedon Oct 20, 2020
+1
gleydsonruan commentedon Oct 21, 2020
+1
jadamec commentedon Feb 10, 2021
+1
chuoke commentedon Apr 13, 2021
sounds so sad
xwiz commentedon Apr 16, 2021
@adrilo I understand you're busy but this is a super useful feature. I've read the guide to contributing and I'm willing to work on this. Do you have any pointers to what has already been tried or your recommendations? I also noticed it's now possible to write cells in v3, this makes the issue of cell merging easier from a technical angle. I can create PRs for both but would love to get pointers so I don't duplicate someone's work.
adrilo commentedon Apr 29, 2021
@xwiz This specific issue is about the automation of the calculation. What's very difficult about this is the fact that you can only determine the width of the column after the last row is written. Which means for each new row, you need to compute the width of each cell and keep the max width. Before closing the writer, the info about the max width needs to be added to the right XML file. Computing the width of a cell may be computationally intensive, especially since Spout supports different fonts (the width of a given text differs from font to font).
Also, we're trying to keep the same features for all file formats (usually XLSX and ODS). So if you're interested to work on that, please remember that. Thanks!
sergiokessler commentedon Sep 9, 2021
absolutely rude hack for someone who need a default width somewhat wider:
in the file
WorksheetManager.phpchange the code:by
note the
defaultColWidthattributte, play with it...xwiz commentedon Sep 12, 2021
@adrilo Missed your reply earlier... will add to my calendar..
jadamec commentedon Oct 10, 2021
+1
cetver commentedon Nov 3, 2021
+1
deivid11 commentedon Jan 6, 2022
+1
sanchezfauste commentedon Feb 3, 2022
+1
Slamdunk commentedon Mar 3, 2022
Static column width settings merged in openspout/openspout#4
Slamdunk commentedon Mar 23, 2022
Hi, just like ODS already did it, with openspout/openspout#45 now also XLSX writes the rows in a temporary file and only after that it writes all the remaining data, thanks to the speed of
stream_copy_to_stream.So now column with, alongside auto-sizing, could be easily supported and already achievable by user code 🚀