Open JemiloII opened 8 years ago
I agree, this would be a good feature, especially for row height when wrapText is true.
Any more development on this? A Cell AutoFit parameter would be great. I'm sure the previous repo had something similar to this.
any workaround for this?
Any fix for this ?
expect this feature!
This feature was brought up before in Issue 23. The problem is that there is no "100%" width in the XML standard. The fix would basically be to add a rendering engine to the library and measure the width of the actual rendered text in the font/size that had been specified. If anyone has another idea, I'd be very open to a pull request.
@natergj I would start by approximating it. See PHPOffice's approach here https://github.com/PHPOffice/PhpSpreadsheet/blob/257c3eca5870dbfaf89eb344fb31c07dfbb74456/src/PhpSpreadsheet/Shared/Font.php#L315
I am using a workaround for this issue:
example for typescript:
const names = ["Alice", "Bob", "Clara"]
const lengthArr = names.map(name => name.length)
const maxWidth = Math.max(...lengthArr)
ws.column(0).setWidth(maxWidth)
that's a pretty good idea. I guess a monospaced font would be ideal then?
I am using a workaround for this issue:
- find max data length for each column
- set column width equal to found max value
example for typescript:
const names = ["Alice", "Bob", "Clara"] const lengthArr = names.map(name => name.length) const maxWidth = Math.max(...lengthArr) ws.column(0).setWidth(maxWidth)
thanks. it's a good solution for one line. how about the wrapText is true? I need to find a way to adjust the row height automatically.
@surfingtomchen, you can divide the text length by the column width (rounded up). E.g. text length is 27 and col width is 10 - row height will be 3. Btw, I don't remember what unit of measure is used for row height, is it a point, pixel or something else, but anyway you can use the found value as coefficient.
@AlexMesser thanks for that one, good solution. It looks like the wrapText: true does not work on excel4node hey? For now just adujsted the width of the column and that seems to do the job :)
Hi Guys, any update on this?
No update?
No update?
@appfrilans "For now just adujsted the width of the column and that seems to do the job :)" That was what I did when I was working on this, did you try it? That solution that was posted above does seem to also get the job done too at least for now.
No update?
@appfrilans "For now just adujsted the width of the column and that seems to do the job :)" That was what I did when I was working on this, did you try it? That solution that was posted above does seem to also get the job done too at least for now.
Yes, setting manual width work but not quite ok if texts vary in length a lot. The issue was for auto-width, not manual.
I am using a workaround for this issue:
- find max data length for each column
- set column width equal to found max value
example for typescript:
const names = ["Alice", "Bob", "Clara"] const lengthArr = names.map(name => name.length) const maxWidth = Math.max(...lengthArr) ws.column(0).setWidth(maxWidth)
Thanks. It's worked for me!
I can't seem to find the option for this. I see things similar to it, but its not it exactly and its api isn't documented well.