gpt4 book ai didi

c# - 如何在单元格A1 :A5 and B1:B5 and C1:C5 with the same color using C#?中填充颜色

转载 作者:太空宇宙 更新时间:2023-11-03 11:40:39 31 4
gpt4 key购买 nike

我目前正在使用以下代码用黄色填充 A1 到 A5 和 B1 到 B5 范围内的单元格:

chartRange1 = xlWorkSheet.get_Range("A1", "A5");
chartRange1.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
Excel.Range chartRange2;
chartRange2 = xlWorkSheet.get_Range("B1", "B5");
chartRange2.Interior.Color= System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);

但它需要 2 个 chartRange 对象才能做到这一点。如果我想在大范围的单元格上设置相同的颜色怎么办?

有没有办法使用一条语句为更大范围的单元格设置相同的颜色来做到这一点?

最佳答案

在您的情况下 (A1:A5, B1:B5, C1:C5) 您可以将单元格合并到一个连续的范围 A1:C5:

xlWorkSheet.get_Range("A1:C5");

但是范围不必是连续的。您还可以使用如下代码:

xlWorkSheet.get_Range("A1:A5,C1:C5,F10:F15");

关于c# - 如何在单元格A1 :A5 and B1:B5 and C1:C5 with the same color using C#?中填充颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4894594/

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