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

"GetCellRichText" and "GetStyle" method do not set font color when white #1794

Closed
Fujita-Naoyuki opened this issue Jan 26, 2024 · 1 comment · Fixed by #1798
Closed

"GetCellRichText" and "GetStyle" method do not set font color when white #1794

Fujita-Naoyuki opened this issue Jan 26, 2024 · 1 comment · Fixed by #1798
Labels
enhancement New feature or request

Comments

@Fujita-Naoyuki
Copy link

Description
"GetCellRichText" and "GetStyle" method do not set font color when white

Steps to reproduce the issue:
1.Call the "GetCellRichText" method for the cell set like the attached image

  • cell value
    image
  • debug
    image

Describe the results you received:
Color: ""

Describe the results you expected:
Color: "FFFFFF"

Output of go version:

go version go1.20.1 windows/amd64

Excelize version or commit ID:

github.com/xuri/excelize/v2 v2.8.0

Environment details (OS, Microsoft Excel™ version, physical, etc.):

@xuri xuri added the enhancement New feature or request label Jan 27, 2024
xxxwang1983 pushed a commit to xxxwang1983/excelize that referenced this issue Jan 29, 2024
@xuri xuri linked a pull request Jan 29, 2024 that will close this issue
10 tasks
xuri pushed a commit that referenced this issue Jan 30, 2024
@xuri
Copy link
Member

xuri commented Jan 30, 2024

Thanks for your issue. There 3 kinds of colors for the text in the spreadsheet: hex color, indexed color, and theme color. The priority of these colors is hex color takes precedence over theme color, and the theme color takes precedence over indexed color. The fields: Color, ColorIndexed, and ColorTheme in the Font data type represent these 3 colors. This library just added a new function GetBaseColor, which supports converting and returns the preferred hex color code from these 3 colors. Please upgrade to the master branch code, and this feature will be released in the next version. In addition, the color also supports applying tint value based on the hex color, so we need to use the ThemeColor function to apply the tint for the based color to get the calculated hex color value. Here is an example for your reference:

runs, err := f.GetCellRichText("Sheet1", "A1")
if err != nil {
    fmt.Println(err)
    return
}
for _, run := range runs {
    var hexColor string
    if run.Font != nil {
        baseColor := f.GetBaseColor(run.Font.Color, run.Font.ColorIndexed, run.Font.ColorTheme)
        hexColor = excelize.ThemeColor(baseColor, run.Font.ColorTint)
    }
    fmt.Printf("text: %s, color: %s\r\n", run.Text, hexColor)
}

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

Successfully merging a pull request may close this issue.

2 participants