Comments (12)
@adrilo but wouldn't the manual sizing be a "quick win" that could solve a lot of our issues? Auto-sizing is a nice-to-have feature, but I would be able to create "good enough" files with manual sizing as well.
Manual sizing and cell merging are the things I'm missing the most in Spout (and consider going back to the PHPExcel, even if it means using 10 times more time and memory).
from spout.
I understand your point and agree with you on that. However we'd rather do the auto-sizing of columns first before tackling the manual option. This is because auto-sizing will benefit more people than manual sizing. But eventually we'll have all options!
from spout.
Although this issue is closed, what's the current thinking around the <cols>
definition in the worksheet xml?
from spout.
"My feeling is that, as a developer, you'd want to control the width of each column separately"
Keep in mind you could set all the column widths individually, I just opened the thread with a lousy example.
i.e,
<col min="1" max="1" width="25" customWidth="1"/>
<col min="2" max="2" width="35" customWidth="1"/>
<col min="3" max="3" width="45" customWidth="1"/>
etc.
is defining separate widths for columns 1, 2, and 3 (respectively widths of 25, 35, and 45).
min and max define the range of columns being affected.
What I would do is, use your method and add two parameters:
$writer->setColumnsWidth(width, min, max) //can be called on numerous columns/column ranges
and you could set the width for each column cleanly.
Its not really a big deal, but its another feature that can be added, which doesnt compromise the library's essential mission of being lightweight, low memory, etc.
from spout.
Hey @5e112, thanks for filing this "issue". Column width is pretty hard to deal with.
In your case, you probably knew in advance the data you were going to output and could therefore adjust the width accordingly. But most of the time, you don't know how long the cell values will be and won't be able to select the appropriate width for the column.
Another way to do it would be to have an auto-width, where we can detect the size of each cell and resize the column to the max size of the columns' cells. Unfortunately, if you want to do this well, it gets pretty complex. Because Spout supports multiple fonts, we can't rely on the size of each character using default font and need to have specific code to determine it in some other ways (this could be done by drawing the text with the given font and get the dimensions of the drawn text). The drawback of this solution is that it takes quite some time for every cell. So for a large spreadsheet, the performance of Spout would be severely degraded.
Now, I may have misunderstood what you were trying to accomplish. Please let me know if that's the case. Or if you had another solution in mind, I'd be happy to discuss about it!
from spout.
If I add text wrapping to the cell, The width is primarily cosmetic. Maybe Im missing something, but I never did any calculations to figure out the widths, I was just suggesting it might be a decent feature to expose through the library, but if not, thats fine, It still suits my purposes.
Again, Thanks for all your hard work. Nice library, really does what I need it to.
from spout.
Oh I see. Do you think the default width is never good? Too small maybe? I could add the <col>
part that you mentioned to change the default width of the columns
from spout.
For large strings, or even paragraphs of text, the default width is a bit rough, definitely too small, sometimes it's a good thing to be able to set a width + text wrapping.
from spout.
Yes, that makes sense. Thinking about how this could be done, the fact that Spout only works on rows and does not know about cells makes it tricky.
You would only be able to set the same width for all the cells of a row. If you can set the columns width for every row, you would basically use the max width in the end:
// terrible interface but it's just an illustration
$sheet->addRowWithCustomWidth(['foo1', 'bar1'], 30);
$sheet->addRowWithCustomWidth(['foo2', 'bar2'], 20); // this width will be ignored
Because of this, it only makes sense to move the scope of this one level higher: defining a custom width for ALL columns. This could be an option on the writer:
$writer = WriterFactory::create(Type::XLSX);
$writer->setColumnsWidth(25);
$writer->openToFile(...);
I'm still unsure if that's going to be very useful. My feeling is that, as a developer, you'd want to control the width of each column separately (which Spout can't do) and not necessarily have a global setting.
Increasing the size of the default column width though (without providing a setter) can be useful.
I'll reopen the issue and wait a bit to see if more people are interested in this improvement.
from spout.
Hello,
I just discover your library and I think @5e112 has a good idea.
Specify column width would really help in my case.
Thank you
from spout.
#129 will be the solution for this. It has the benefits of being transparent for the developer. Spout should be able to automatically adjust the dimensions of the cells based on its content.
Developers will be able to specify the max width and max height and Spout will take care of the rest!
I'm closing this issue and will track the progress in #129
from spout.
I'm posting a little late on this, but it seems obvious to me that the developer should have the power, if he or she so chooses, to "globally" set a column width. This is a valid decision, and it can and will often mean a) "This is what I know I want the width to be" and/or b) "Content can get large in this column, I don't want it to go beyond x width, so this way I can set it and forget it"
Giving this option in Box/spout is analogous to the user being able to do this manually in the Excel UI. Those who have never done that before, please raise your hand :)
from spout.
Related Issues (20)
- Thanks to package authors! How does it work? HOT 1
- Style not present when editing existing spreadsheet
- It takes around 5 secs to read 1000 rows (25 cols) HOT 1
- This page isn’t working when calling $reader = ReaderEntityFactory:: HOT 1
- Previous issue #861 prematurely closed HOT 4
- Support Excel cell Comments HOT 2
- Unable to open source data
- Trying to add vertical alignment and fix textWrap for XLSXWriter HOT 1
- Add option to change the encoding of the whole exported csv file (not only the content) HOT 1
- PHP 8.1 Error HOT 4
- Incorrect type reported when adding an unsupported type to a cell
- Percentage type reading supported? HOT 1
- Content-Disposition header for file download is not properly encoded HOT 1
- Format date on export XLSX
- Is it possible to use wb instead of wb+ fopen mode in openToFile() in AbstractWriter in order to use compress.zlib:// ? HOT 5
- PHP 8.1 Warnings HOT 2
- Doing cell->getValue() on loop stops when the value is a DateTime Object
- rowIterator->next() crash HOT 5
- rowIterator->next()
- Count total number of rows for XLSX HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spout.