is there a way to auto fit columns?
^ title, is there a way to auto fit columns (auto width)?
If not, how to set the width on all cols to fit the content?
Thanks for your issue. To auto fit columns width, we need to calculate the column width based on the calculated value of the column (so on the result of any formulae, we need to implement formula calculation engine first), and any additional characters added by format masks such as thousand separators, and set the width, bestFit(this property is an information property, we still need to provide the width for the column) and customWidth properties of the columns. That's an interesting job and I will consider adding support for this feature later. But now there is no way to set that. I'll certainly accept that patch if somebody did that.
Hello,
Just want to know if there is still no solution ?
Thank's for your amazing job !
@unkls I'm sorry, this feature has not yet been developed. There's a lot of things it could do with, but I'm not really able to commit more time to this project right now.
I want to set auto col and height, but...,
hope for this feature
Is this Feature ready yet? Or If nobody is working on it, let me know If I can help in anyway, @xuri
Thank you for your hard work. Please let us know if this feature will be available anytime soon
You can do something like this :
// Autofit all columns according to their text content
cols, err := f.GetCols(sheetName)
if err != nil {
return err
}
for idx, col := range cols {
largestWidth := 0
for _, rowCell := range col {
cellWidth := utf8.RuneCountInString(rowCell) + 2 // + 2 for margin
if cellWidth > largestWidth {
largestWidth = cellWidth
}
}
name, err := excelize.ColumnNumberToName(idx + 1)
if err != nil {
return err
}
f.SetColWidth(sheetName, name, name, float64(largestWidth))
}
Inspired from https://github.com/tealeg/xlsx/pull/618 It just works for string cells.
I'm not sure how it should be implemented into this library though. I did not find an effective way to get all cells for a column.
We could take inspiration from the library SpreadsheetLight for .NET.
I've used for a reasonable time and the auto fit feature works great..
https://github.com/jmsanmu/SpreadsheetLight/blob/fa9ab90bab19654868d100c0b1fee0ca613f7ffd/source/RowColumnFunctions.cs#L2492
Any news on this?
Is there any way to do this currently?
We could take inspiration from the library SpreadsheetLight for .NET. I've used for a reasonable time and the auto fit feature works great..
https://github.com/jmsanmu/SpreadsheetLight/blob/fa9ab90bab19654868d100c0b1fee0ca613f7ffd/source/RowColumnFunctions.cs#L2492
well, let me do some research on this C# code...
Also keep in mind it can become troublesome if we have different fonts in the same column. The same number of characters will occupy a different space depending on the font. 😉
Hello, When can this PR be merged into the main branch? I really need this feature
Hello, When can this PR be merged into the main branch? I really need this feature
All code review issues of PR #1386 should be resolved before merging it.