我需要在 excel 中搜索几个单词并突出显示这些单词。已将单词保存在 xml 文件中。下面是正在使用的代码。该范围甚至需要花费更多时间的 null 并且它读取整行(在字符串中)而不是读取 excel 中的每个单词。请帮忙
for (int i = 1; i < xmlnode.Count; i++)
{
XmlAttributeCollection xmlattrc = xmlnode[i].Attributes;
object text = xmlnode[i].FirstChild.InnerText;
string str;
int rCnt = 0;
int cCnt = 0;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet1;
Excel.Range range;
xlWorkSheet1 = (Excel.Worksheet)doc1.Worksheets.get_Item(1);
range = xlWorkSheet1.get_Range("A1","A10");
for (rCnt = 1; rCnt <= range.Rows.Count; rCnt++)
{
for (cCnt = 1; cCnt <= range.Columns.Count; cCnt++)
{
str = (string)(range.Cells[rCnt, cCnt] as Excel.Range).Value2; //am getting the whole row but i need to read each word seperately
if (str == text.ToString())
{
range.Font.Bold = 1;
range.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);
}
}
}
}