gpt4 book ai didi

c# - 在excel中获取单元格的内部颜色

转载 作者:太空宇宙 更新时间:2023-11-03 16:09:01 24 4
gpt4 key购买 nike

我需要在 excel 中用金色突出显示包含错误数据的单元格,我可以做到。但是一旦用户更正数据并单击验证按钮,内部颜色应该恢复为原始内部颜色。这没有发生。请指出错误。并且请提供确切的代码,因为我已经尝试了很多东西,但到目前为止没有任何效果。

private void ValidateButton_Click(object sender, RibbonControlEventArgs e)
{
bool LeftUntagged = false;
Excel.Workbook RawExcel = Globals.ThisAddIn.Application.ActiveWorkbook;
Excel.Worksheet sheet = null;
Excel.Range matrix = sheet.UsedRange;
for (int x = 1; x <= matrix.Rows.Count; x++)
{
for (int y = 1; y <= matrix.Columns.Count; y++)
{
string CellColor = sheet.Cells[x, y].Interior.Color.ToString();
if (sheet.Cells[x, y].Value != null && (Excel.XlRgbColor.rgbGold.Equals(sheet.Cells[x, y].Interior.Color) || Excel.XlRgbColor.rgbWhite.Equals(sheet.Cells[x, y].Interior.Color)))
{
sheet.Cells[x, y].Interior.Color = Color.Transparent;
}
}
}
}

最佳答案

我实现了我想做的事情。这是解决方案:

private void ValidateButton_Click(object sender, RibbonControlEventArgs e)
{
bool LeftUntagged = false;
Excel.Workbook RawExcel = Globals.ThisAddIn.Application.ActiveWorkbook;
Excel.Worksheet sheet = null;
Excel.Range matrix = sheet.UsedRange;
for (int x = 1; x <= matrix.Rows.Count; x++)
{
for (int y = 1; y <= matrix.Columns.Count; y++)
{
string CellColor = sheet.Cells[x, y].Interior.Color.ToString(); //Here I go double value which is converted to string.
if (sheet.Cells[x, y].Value != null && (CellColor == Color.Transparent.ToArgb().ToString() || **CellColor == Excel.XlRgbColor.rgbGold.GetHashCode().ToString()**))
{
sheet.Cells[x, y].Interior.Color = Color.Transparent;
}
}
}
}

关于c# - 在excel中获取单元格的内部颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18211443/

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