本文介绍了C#查找列是否包含“N”。如果是,则删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好我有一个excel文件,并且每列都有一个Y或N的列,如果它包含N但是我想删除该行,但是要对条件进行检查以查看它。 我的尝试: <预> Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook sheet = excel.Workbooks.Open(C:\\Data\\Enrolled.xlsx); Microsoft.Office.Interop.Excel.Worksheet x = excel.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet; int i = 0; for(i = 1; i< = lastRow; i ++) { //条件需要检查列行是否有N if(excel.WorksheetFunction )(x.Rows [i] as Microsoft.Office.Interop.Excel.Range).Delete(); } sheet.Close(true,Type.Missing,Type.Missing); excel.Quit(); 解决方案 Hello I have an excel file, and there is a column that has either "Y" or "N" for each row and I would like to delete the row if it contains "N" but struggling with the conditional to check it.What I have tried:<pre> Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook sheet = excel.Workbooks.Open("C:\\Data\\Enrolled.xlsx"); Microsoft.Office.Interop.Excel.Worksheet x = excel.ActiveSheet as Microsoft.Office.Interop.Excel.Worksheet; int i = 0; for (i = 1; i <= lastRow; i++) { // Conditional Needed to check if column row has a "N" if (excel.WorksheetFunction) (x.Rows[i] as Microsoft.Office.Interop.Excel.Range).Delete(); } sheet.Close(true, Type.Missing, Type.Missing); excel.Quit(); 解决方案 这篇关于C#查找列是否包含“N”。如果是,则删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!