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

SetCellStyle doesnt work on macos excel #2110

Closed
2 tasks done
mc2j73 opened this issue Mar 25, 2025 · 2 comments
Closed
2 tasks done

SetCellStyle doesnt work on macos excel #2110

mc2j73 opened this issue Mar 25, 2025 · 2 comments
Labels
needs more info This issue can't reproduce, need more info

Comments

@mc2j73
Copy link

mc2j73 commented Mar 25, 2025

Description

When i create a file with NewStyle and SetCellStyle, style alignment didnt apply

After double click on cell, it work

But on Ubuntu 24 it works as expected

Steps to reproduce the issue

Create new style

breakLineStyle, err := file.NewStyle(&excelize.Style{
	Alignment: &excelize.Alignment{
		WrapText: true,
	},
})

SetStyle
err = file.SetCellStyle(sheetName, cell, cell, breakLineStyle)

Describe the results you received

Image

Alignment didnt apply

Image

When I doubleclick on cell, it work properly

Describe the results you expected

Image

And applied alignment

Image

Go version

1.22

Excelize version or commit ID

v2.8.1

Environment

MacOs Sonoma 14.4
Excel 2019 for mac

Validations

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.
@xuri
Copy link
Member

xuri commented Mar 26, 2025

Thanks for your issue. Note that the text only wrapping when characters overflow the column width. I tested with following code and it works well, the "Wrap Text" button is activated after open generated workbook in the Excel application:

package main

import (
    "fmt"

    "github.com/xuri/excelize/v2"
)

func main() {
    file := excelize.NewFile()
    defer func() {
        if err := file.Close(); err != nil {
            fmt.Println(err)
        }
    }()
    breakLineStyle, err := file.NewStyle(&excelize.Style{
        Alignment: &excelize.Alignment{
            WrapText: true,
        },
    })
    if err != nil {
        fmt.Println(err)
    }
    if file.SetCellStyle("Sheet1", "A1", "A1", breakLineStyle); err != nil {
        fmt.Println(err)
    }
    if err := file.SetCellValue("Sheet1", "A1", "line1line2line3"); err != nil {
        fmt.Println(err)
    }
    if err := file.SaveAs("Book1.xlsx"); err != nil {
        fmt.Println(err)
    }
}

Could you show us a complete, standalone example program or reproducible demo?

@xuri xuri added the needs more info This issue can't reproduce, need more info label Mar 26, 2025
@mc2j73
Copy link
Author

mc2j73 commented Mar 28, 2025

I swear, it didnt work two days ago, but now all works fine

I think, problem was that I write (with SaveAs) in existing file. When i write in new file, it works fine

Thank you!

@mc2j73 mc2j73 closed this as completed Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info This issue can't reproduce, need more info
Projects
None yet
Development

No branches or pull requests

2 participants