Hi,
I think your desired code will look like to the below one, try to test the code in console application by creating a Test.xlsx excel file with some used cells (like make the first rows dirty with inserting letters or numbers into them) then make the back color black. Just do not forget to reference Microsoft.Office.Interop.Excel in your project. Keep in your mind you need a better exception handling and also SOLID implementation the below code is only a small indication of your final work.
static void Main(string[] args)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
xlApp = new Excel.Application();
try
{
xlWorkBook = xlApp.Workbooks.Open(@"C:\Test\Test.xlsx");
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets[1];
var rows = xlWorkSheet.UsedRange;
foreach (Excel.Range row in rows)
{
double color = row.Interior.Color;
if (color == 0)
row.Delete();
}
xlWorkBook.Save();
xlWorkBook.Close();
}
catch (Exception)
{
throw;
}
finally
{
xlApp.Quit();
Marshal.ReleaseComObject(xlApp);
}
}
Cheers,
--AH.