-
-
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
Display order of conditional formats at the same location #1770
Comments
Thanks for your issue. I have fixed some problems with setting and getting conditional formats with multiple rules, please upgrade to the master branch. If it still doesn't work, please let me know. |
I am using the latest release, but it doesn't seem to be taking effect... |
Thanks for your feedback. Could you show us a complete, standalone example program or reproducible demo? I have tested with the following code and it works well. The priority of the conditional formatting rule with a blue color data bar is in the expected: package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
defer func() {
if err := f.Close(); err != nil {
fmt.Println(err)
}
}()
var condFmts []excelize.ConditionalFormatOptions
for _, color := range []string{
"#264B96", // Blue
"#F9A73E", // Yellow
"#006F3C", // Green
} {
condFmts = append(condFmts, excelize.ConditionalFormatOptions{
Type: "data_bar",
Criteria: "=",
MinType: "num",
MaxType: "num",
MinValue: "0",
MaxValue: "20",
BarColor: color,
BarSolid: true,
})
}
if err := f.SetConditionalFormat("Sheet1", "A1:A20", condFmts); err != nil {
fmt.Println(err)
return
}
for r := 1; r <= 20; r++ {
cell, err := excelize.CoordinatesToCellName(1, r)
if err != nil {
fmt.Println(err)
return
}
if err := f.SetCellValue("Sheet1", cell, r); err != nil {
fmt.Println(err)
return
}
}
if err := f.SaveAs("Book1.xlsx"); err != nil {
fmt.Println(err)
}
} |
ok,if you set two column,the problem will be shown package main
import (
"fmt"
"github.com/xuri/excelize/v2"
)
func main() {
f := excelize.NewFile()
defer func() {
if err := f.Close(); err != nil {
fmt.Println(err)
}
}()
var condFmts []excelize.ConditionalFormatOptions
for _, color := range []string{
"#264B96", // Blue
"#F9A73E", // Yellow
"#006F3C", // Green
} {
condFmts = append(condFmts, excelize.ConditionalFormatOptions{
Type: "data_bar",
Criteria: "=",
MinType: "num",
MaxType: "num",
MinValue: "0",
MaxValue: "20",
BarColor: color,
BarSolid: true,
})
}
if err := f.SetConditionalFormat("Sheet1", "A1:A20", condFmts); err != nil {
fmt.Println(err)
return
}
if err := f.SetConditionalFormat("Sheet1", "B1:B20", condFmts); err != nil {
fmt.Println(err)
return
}
for r := 1; r <= 20; r++ {
cell, err := excelize.CoordinatesToCellName(1, r)
if err != nil {
fmt.Println(err)
return
}
if err := f.SetCellValue("Sheet1", cell, r); err != nil {
fmt.Println(err)
return
}
cell, err = excelize.CoordinatesToCellName(2, r)
if err != nil {
fmt.Println(err)
return
}
if err := f.SetCellValue("Sheet1", cell, r); err != nil {
fmt.Println(err)
return
}
}
if err := f.SaveAs("Book1.xlsx"); err != nil {
fmt.Println(err)
}
} when you go run this demo,you can see the columnA's color is right,but the columnB's color is the second priority's color |
…riorities - Rename variable name hCell to topLeftCell, and rename vCell to bottomRightCell - Update the unit tests
Thanks for your issue. I have fixed this. Please upgrade to the master branch code, and this patch will be released in the next version. |
Description
Use SetConditionalFormat() to set multiple conditional formats for data bars in a location such as A1: A13, such as blue (1), green (2), and yellow (3). When opened in Excel, the effect will be green, while the management conditional format interface will prioritize blue. Set the same number of data bar conditional formats and priorities in the same location in Excel, but their XML structures are the same. After comparing products such as Feishu and Tencent Documents, it was found that their display order is right, and the writing structure of conditional formats is different from that of excelize,Can you refer to their approach to modify SetConditionalFormat to achieve consistent rendering effects and priority ? thanks.
this is excel xml
this is excelize xml
** this is feishu\Tencent xml**
Diffence
img.xlsx
dd.xlsx
excelize.xlsx
The text was updated successfully, but these errors were encountered: