如何根据给定范围中的字体颜色选择Excel单元格 [英] How to select Excel Cell based on Font Color in the Given Range

查看:63
本文介绍了如何根据给定范围中的字体颜色选择Excel单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 

我使用VSTO和C#实现了Excel加载项。

I have implemented an Excel Add-in using VSTO and C#.

我必须选择一个单元格,基于给定范围内的字体颜色。

I have to select one cell, based on the Font Color in the Given Range.

任何人都可以帮我解决这个问题。

Can anyone please help me out how to do this.

谢谢

Nihar

推荐答案

嗨NiharSai,

Hi NiharSai,

你可以迭代细胞给定范围并检查单元格'

Font.Color属性
。如果你得到你想要的颜色,那么你可以选择单元格并退出迭代。

You could iterate through cells in the given range and check the cells Font.Color Property. If you get the color you want, then you could select the cell and exit iterating.

这是一个例子。

            Excel中应用程序
xlApp =
Globals 。ThisAddIn .Application;

        ;     Excel。 工作表
xlWorksheet = xlApp.ActiveSheet;

<跨度风格=" 字体大小:9.5pt;字型家族:索拉">&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Excel。 范围
givenRange = xlWorksheet.Range [" A1:D10" ];

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
foreach (Excel。 范围
cell
givenRange.Cells){

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
if (cell.Font.Color == System.Drawing。 ColorTranslator 。ToOle(System.Drawing。 颜色 。红色))
{

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP; cell.Select();

      &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
return ;

      &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }

         ;&NBSP;&NBSP;&NBSP; }

最好的问候,

Terry


这篇关于如何根据给定范围中的字体颜色选择Excel单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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