I want to find a remove any cell which is empty (doesn't contain a value or style). I'm trying to do this using Excel.Interop. I'm not entirely sure how to go about this but I tried this.
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
Excel.Range range;
string str;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(@"C:\Users\Craig\Desktop\testCell.xlsx", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
range = xlWorkSheet.UsedRange;
if ((((Excel.Range)xlWorkSheet.Cells[range]).Value2.ToString() != String.Empty))
{
Console.WriteLine("No empty cells found");
}
else
Console.WriteLine("Found empty cells");
However I get a run time saying The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
On my if statement. Any ideas on my issue or if I'm going about this the correct way? I've went into my Temporary files and removed them plus I removed the content of my bin folder