-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is there a way to auto fit columns? #92
Comments
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 |
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? |
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 tealeg/xlsx#618 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 |
Any news on this? Is there any way to do this currently? |
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, |
All code review issues of PR #1386 should be resolved before merging it. |
^ 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?
The text was updated successfully, but these errors were encountered: