c#excel如何改变特定行的颜色

我想问你们,如果单元格1不为空,如何在Excel表格中将行的颜色更改为红色。

XX YY ZZ ----------------- aa bb cc aa1 bb1 cc1 aa2 cc2 aa3 bb3 cc3 aa4 

 Excel.Application xlApp; Excel. Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; 

我非常感谢

给这一个镜头,我已经testing它,它的工作原理:

 Excel.Application application = new Excel.Application(); Excel.Workbook workbook = application.Workbooks.Open(@"C:\Test\Whatever.xlsx"); Excel.Worksheet worksheet = workbook.ActiveSheet; Excel.Range usedRange = worksheet.UsedRange; Excel.Range rows = usedRange.Rows; int count = 0; foreach (Excel.Range row in rows) { if (count > 0) { Excel.Range firstCell = row.Cells[1]; string firstCellValue = firstCell.Value as String; if (!string.IsNullOrEmpty(firstCellValue)) { row.Interior.Color = System.Drawing.Color.Red; } } count++; } workbook.Save(); workbook.Close(); application.Quit(); Marshal.ReleaseComObject(application); 
 Excel.Application xlAppToExport = new Excel.Application(); xlAppToExport.Workbooks.Add(""); Excel.Worksheet xlWorkSheetToExport = default(Excel.Worksheet); xlWorkSheetToExport = (Excel.Worksheet)xlAppToExport.Sheets["Sheet1"]; xlWorkSheetToExport.Range["A5:F5"].EntireRow.Interior.Color = System.Drawing.Color.Gray;