Skip to content
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

Open
OneOfOne opened this issue Aug 2, 2017 · 14 comments · May be fixed by #1386
Open

is there a way to auto fit columns? #92

OneOfOne opened this issue Aug 2, 2017 · 14 comments · May be fixed by #1386

Comments

@OneOfOne
Copy link

OneOfOne commented Aug 2, 2017

^ 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?

@xuri
Copy link
Member

xuri commented Aug 3, 2017

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.

@unkls
Copy link

unkls commented May 9, 2018

Hello,

Just want to know if there is still no solution ?

Thank's for your amazing job !

@xuri
Copy link
Member

xuri commented May 9, 2018

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

@imyuliz
Copy link

imyuliz commented Sep 25, 2019

I want to set auto col and height, but...,

@imom0
Copy link

imom0 commented Feb 25, 2020

hope for this feature

@hinupurthakur
Copy link

hinupurthakur commented Sep 21, 2020

Is this Feature ready yet?
Or If nobody is working on it, let me know If I can help in anyway, @xuri

@BinodKafle
Copy link

Thank you for your hard work. Please let us know if this feature will be available anytime soon

@gnuletik
Copy link

gnuletik commented Apr 16, 2021

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

@mniak
Copy link

mniak commented May 17, 2021

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

@eduardo-mior
Copy link

Any news on this?

Is there any way to do this currently?

@gucio321
Copy link

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

@yyt030 yyt030 linked a pull request Nov 5, 2022 that will close this issue
10 tasks
@xuri xuri linked a pull request Mar 8, 2023 that will close this issue
10 tasks
@qdm12
Copy link

qdm12 commented Sep 27, 2023

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

@tangbo1430
Copy link

Hello,
When can this PR be merged into the main branch? I really need this feature

@xuri
Copy link
Member

xuri commented May 4, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.