locked
File Data Clean Up RRS feed

  • Question

  • I have excel file Or Csv

    Data available from 19 th row to 20000 row

    Before 19 th row what ever is there it should delete.

    After 20000 row if file contains any data should delete.

    Scenario2:

    If data exist upto 30000  row after 30001 row onwards it should delete unwanted data.

    Tuesday, September 1, 2020 12:21 PM

All replies

  • Hello,

    Since we don't write code for you please show us what you have tried so far.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, September 1, 2020 1:18 PM
  • Hi harikiran2010,

    You can use Range.Delete Method to delete rows.

    Like this, I delete the first two lines:

                ApplicationClass excel = new ApplicationClass();
                Workbook workbook = excel.Workbooks.Open(@"D:\test\excel\2.xlsx");
                Worksheet worksheet = (Worksheet)workbook.ActiveSheet;
                int startRow = 1;
                int endRow = 2;
                for (int i = startRow; i < endRow; i++)
                {
                    ((Range)worksheet.Rows[i]).Delete(XlDeleteShiftDirection.xlShiftUp);
                }
                workbook.Save();
                workbook.Close();
                excel.Quit();

    This code needs to install a nuget package first:Microsoft.Office.Interop.Excel

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, September 9, 2020 7:06 AM
  • The question does look like homework or offline interview tasks.

    In this case it's better to ask what the asker have done so far, like what Kareninstructor do here, instead of directly posting answers.

    EDIT: Okay I see you're not posting direct answer either.

    Wednesday, September 9, 2020 8:10 AM
    Answerer