Git Product home page Git Product logo

Comments (12)

borys-p avatar borys-p commented on August 25, 2024 4

@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.

adrilo avatar adrilo commented on August 25, 2024 3

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.

jmitchell38488 avatar jmitchell38488 commented on August 25, 2024 3

Although this issue is closed, what's the current thinking around the <cols> definition in the worksheet xml?

from spout.

5e112 avatar 5e112 commented on August 25, 2024 2

"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.

adrilo avatar adrilo commented on August 25, 2024

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.

5e112 avatar 5e112 commented on August 25, 2024

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.

adrilo avatar adrilo commented on August 25, 2024

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.

5e112 avatar 5e112 commented on August 25, 2024

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.

adrilo avatar adrilo commented on August 25, 2024

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.

 avatar commented on August 25, 2024

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.

adrilo avatar adrilo commented on August 25, 2024

#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.

samfullman avatar samfullman commented on August 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.