C# Delete Blank Cells

Viewed 713
    public static void ExportData()
    {
        Microsoft.Office.Interop.Excel.Application xlexcel;
        Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
        Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
        object misValue = System.Reflection.Missing.Value;
        xlexcel = new Excel.Application();
        xlexcel.Visible = true;
        xlWorkBook = xlexcel.Workbooks.Add(misValue);
        xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
        xlWorkBook.Application.ScreenUpdating = false;
        Excel.Range CR = (Excel.Range)xlWorkSheet.Cells[1, 1];
        CR.Select();
        xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);
        Excel.Range DR = (Excel.Range)xlWorkSheet.Columns["A:A"];
        DR.Select();
        DR.Delete();
        Excel.Range A1 = (Excel.Range)xlWorkSheet.Cells[1, 1];
        A1.Select();
    }

This is current function I have. At the end I would like to replicate this VB code from Excel that I have ;

    Columns("A:A").Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.EntireRow.Delete

I've tried a few different options replacing "Selection" but the closest I got to, was making the C# side select the blank cells, but then it would delete EVERYTHING instead of just the selected text.

Anybody have a direction I can go in please?

Also using ;

using Excel = Microsoft.Office.Interop.Excel;
2 Answers
Related