none
In OLEDB,how to delete blank row ?C# RRS feed

  • Question

  • Hello Everyone. In my application, I use OLEDB to merge multiple excels into one. I complete the merge, data is no problem,but  cause many black rows. Then  any way to delete them ?  Thx.

    Wednesday, April 22, 2015 2:35 AM

Answers

  • Refer this article.

    Try the following code:

    Excel.Range range = worksheet.UsedRange;
    int rowcount = range.Rows.Count;
    for (int i = 1; i < rowcount; i++)
      {
         Excel.Range rg = worksheet.get_Range("A" + i.ToString());
         if (Convert.ToString(rg.Value2)==null)
            {
                 ((Excel.Range)worksheet.Range["A" + i.ToString(), _columnEnd + i.ToString()]).EntireRow.Delete(null);
                        i--;
                        rowcount--;
             }
       }

    --------------------------------------------------------

    Free C# PowerPoint component is under evaluation, any suggestions.

    • Marked as answer by L.HlModerator Wednesday, May 6, 2015 5:39 AM
    Wednesday, April 22, 2015 2:42 AM

All replies

  • Check this post,and refer his delete way. Check to see if the row was empty then delete it using the example as a starting point. Hope helpful!



    Wednesday, April 22, 2015 2:39 AM
  • Refer this article.

    Try the following code:

    Excel.Range range = worksheet.UsedRange;
    int rowcount = range.Rows.Count;
    for (int i = 1; i < rowcount; i++)
      {
         Excel.Range rg = worksheet.get_Range("A" + i.ToString());
         if (Convert.ToString(rg.Value2)==null)
            {
                 ((Excel.Range)worksheet.Range["A" + i.ToString(), _columnEnd + i.ToString()]).EntireRow.Delete(null);
                        i--;
                        rowcount--;
             }
       }

    --------------------------------------------------------

    Free C# PowerPoint component is under evaluation, any suggestions.

    • Marked as answer by L.HlModerator Wednesday, May 6, 2015 5:39 AM
    Wednesday, April 22, 2015 2:42 AM