gpt4 book ai didi

conditional-formatting - 使用 Epplus 读取电子表格并确定所有单元格的样式,包括有条件的格式

转载 作者:行者123 更新时间:2023-12-04 08:40:42 25 4
gpt4 key购买 nike

我正在使用 Epplus (C#.net) 读取电子表格中 protected 和锁定的单元格的值和样式(背景和字体颜色)。

样式.填充.背景颜色.Rgb; Style.Fill.BackgroundColor.Theme 和 Style.Font.Color.Rgb;样式.字体.颜色在大多数细胞中正常工作。我遇到了使用条件格式“仅格式化唯一值或重复值”的单元格的问题。背景和字体颜色从 Epplus 返回为 null。

这是从特定单元格获取背景/字体颜色的代码

    private ExcelStyleLoad GetStyleInfo(ExcelRange currentCell)
{
ExcelStyleLoad retval = new ExcelStyleLoad();
//background
retval.BackgroundColor = currentCell.Style.Fill.BackgroundColor.Rgb;
retval.BackgroundTheme = currentCell.Style.Fill.BackgroundColor.Theme;

//font
retval.FontColor = currentCell.Style.Font.Color.Rgb;
retval.FontTheme = currentCell.Style.Font.Color.Theme;

//other
retval.isBold = currentCell.Style.Font.Bold;
retval.isUnderline = currentCell.Style.Font.UnderLine;
retval.isItalics = currentCell.Style.Font.Italic;

retval.FullAddress = currentCell.FullAddress;
return retval;
}

我也曾尝试使用 currentCell.ConditionalFormatting.AddDuplicateValues() 来确定背景/字体颜色,但没有成功。

关于如何获得使用 ConditionalFormatting 的单元格的背景/字体颜色的任何建议?

最佳答案

据我了解,具有条件格式的单元格(不一定)具有背景颜色,它们仅具有条件格式规则。背景颜色是根据工作表显示时的值和规则推断的。

这符合您的观察。

因此您必须在单元格中查找条件格式,并在读取格式时自行计算颜色值。在工作表受到保护和锁定的情况下,希望不大。

无论如何,即使在 protected 和锁定的工作表中,您也应该能够确定唯一/重复的单元格。祝你好运!

关于conditional-formatting - 使用 Epplus 读取电子表格并确定所有单元格的样式,包括有条件的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56229440/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com