c# - C# 选择现有 Excel 文件中的特定行
问题描述
您好我想知道如何突出显示现有 Excel 文件中具有相同值的单元格。我的 excel 文件包含更多带有名称的行。我想要突出显示与我在文本框中使用的名称相同的名称。
string workbookPath = @"PathOfExcelFile";
_Excel.Application ExcelApp = new _Excel.Application();
ExcelApp.Visible = true;
_Excel.Workbook workbook = ExcelApp.Workbooks.Open(workbookPath);
_Excel.Worksheet worksheet = workbook.ActiveSheet;
_Excel.Range selectRange;
selectRange = worksheet.get_Range(""); //
谢谢
解决方案
这是我突出单元格的建议:
//find last cell if needed
int lastCell = xlWorkSheet.Cells.Find(
"*",
System.Reflection.Missing.Value,
Excel.XlFindLookIn.xlValues,
Excel.XlLookAt.xlWhole,
Excel.XlSearchOrder.xlByRows,
Excel.XlSearchDirection.xlPrevious,
false,
System.Reflection.Missing.Value,
System.Reflection.Missing.Value).Row;
Excel.Range rangeCheck = xlWorkSheet.Range["A1:A" + lastCell];
foreach (Excel.Range cell in rangeCheck.Cells)
{
string checkStrigng = Convert.ToString(cell.Value);//converts cell value to string for comparision
if (checkString == textbox.Text)
{
cell.Interior.Color = System.Drawing.Color.Yellow;
}
}
推荐阅读
- javascript - 道具在“render”函数中工作时在“render”函数上方显示空值?
- javascript - react.js 文档中的 HOC
- reactjs - 即使我正在清理我的 useEffect,如何避免我的反应应用程序中的内存泄漏警告?
- kotlin - 如果变量不为空,则分配给变量的更简洁方法
- python-3.x - 如何使用python将一串像素转换为图像?
- git - 如何在不删除文件、数字和重复的情况下存储“git pull”的输出,以便在文本文件中列出新文件?
- c# - 使方法参数不合格
- scala - 如何在 udf 中使用数据框并在 spark scala 中解析数据
- mysql - 对话 SQL 结构(群聊)
- ghci - GHCi 中的 PrimOps