如何使用C#更改excel单元格的颜色 [英] How I can change the color an excel cell using C#

查看:823
本文介绍了如何使用C#更改excel单元格的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!

我的英语不是很好,所以试着理解我



我想用c#自动化一个过程,但是有一个很多信息,我需要改变一些细胞的颜色,但我不知道名字在哪里,







请帮帮我



谢谢



我试过的:



i allready使用System.Drawing但我不知道如何使用它,我尝试用if,但我避风港没有成功。

Hello!
My english isn't very well, so try to understand me

I want to automate a process with c#, but there is a lot of information, i need to change the color of some cells, but i don't know where is the name,



Please help me

Thanks

What I have tried:

i allready use the System.Drawing but i don't know how i can use it, i try to do with a if, but i haven't success.

推荐答案

System.Drawing不会帮助改变excel单元格的颜色。您没有说明如何访问excel文件。但是,您正在访问excel文件(使用下面的互操作),您必须通过获取其范围来解决要更改颜色的单元格,然后根据需要设置内部颜色和字体颜色。示例:使用下面的互操作:

System.Drawing is not going to help changing the color of an excel cell. You do not say how you are accessing the excel file. However you are accessing the excel file (using interop below) you will have to address the cell you want to change the color by getting its range, then setting the Interior color and font color if needed. Example: using interop below:
Range range = MySheet.get_Range("B3");
string someValue = "ValueToFlag";
if (range.Value.ToString() == someValue) {
  range.Interior.Color = Color.Red;
  range.Font.Color = Color.Yellow;
}
else {
  range.Interior.Color = Color.White;
  range.Font.Color = Color.Black;
}
Console.ReadKey();


检查:如何:以编程方式将颜色应用于Excel范围 [ ^ ]


以及 Maciej Los [ ^ ]解决方案,如果您使用的是 EPPlus [ ^ ]然后试试这个

openxml - 使用epplus c#设置Excel工作表单元格的自定义BackgroundColor - Stack Overflow [ ^ ]
in addition to Maciej Los [^] solution, if you are using EPPlus [^] then try this
openxml - Set custom BackgroundColor of a Excel sheet cell using epplus c# - Stack Overflow[^]


这篇关于如何使用C#更改excel单元格的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆