【问题标题】:Spreadsheetgear - Add background color via conditional formattingSpreadsheetgear - 通过条件格式添加背景颜色
【发布时间】:2020-06-10 16:10:18
【问题描述】:

当单元格的值超过某个阈值时,我正在尝试使用条件格式添加鲑鱼背景颜色。这是我的代码:

Dim condition As IFormatCondition = thisRow(0, 6).FormatConditions.Add(FormatConditionType.CellValue, FormatConditionOperator.GreaterEqual, 0.035, Nothing)
condition.Interior.Color = Drawing.Color.FromArgb(230, 184, 183)

条件已正确创建,但无论出于何种原因,它没有将背景颜色设置为鲑鱼,而是使用 rgb(192, 192, 192)。

我做错了什么?

【问题讨论】:

标签: excel vb.net spreadsheetgear


【解决方案1】:

想到两种可能性:

  1. 您使用的是 SpreadsheetGear 2012 (V7) 或更早版本。这些旧版本的 SpreadsheetGear 对条件格式 (CF) 的支持有限——其中之一是对 24 位颜色的有限支持。当您为不在工作簿的 56 色调色板 (IWorkbook.Colors) 中的 CF 指定任意 24 位颜色时,SpreadsheetGear 会将提供的颜色映射到调色板中最接近的匹配。

    SpreadsheetGear 2017 / V8 大大改进了对条件格式的支持,包括使用任意 24 位 RGB 颜色的能力,因此升级可以解决这个问题。

  2. 您正在保存为较旧的 Excel 97-2003 (*.xls) 文件格式。即使您使用的是 SpreadsheetGear 2017+,如果您保存为这种较旧的文件格式,CF 也会丢失 24 位颜色,并再次映射到工作簿的 56 色调色板中最接近的颜色。在这种情况下,最好保存为 Open XML(*.xlsx 或 *.xlsm)文件格式,它确实支持完整的 24 位颜色。

【讨论】:

  • 是的,我使用的是 2012 年的旧版本。我将颜色线更新为condition.Interior.Color = Colors.LightSalmon,它就像一个魅力。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-06-23
  • 1970-01-01
相关资源
最近更新 更多