Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear EveryBody!
My English is not good.
I'm writing an application to combine multiple excel files into one file using OLEDB, the program runs fine now.
But I encountered a problem when excel file with multiple blank rows, I do not know how to delete the empty rows?
Would like to receive the help from everyone!
Thank you!
Posted
Updated 22-Aug-14 0:33am
v2

http://stackoverflow.com/questions/9951188/deleting-rows-from-an-excel-file-using-c-sharp[^]

I would then check to see if the row was empty then delete it using the example as a starting point.


Good luck.
 
Share this answer
 
 
Share this answer
 
Dear Slacker007, CB Sharma!
First, thank you for your help 2.
The help of the two of you is very helpful for me.
Thanks to your help, my problem was solved.
Code demo:

C#
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--;
         }
   }
 
Share this answer
 
v3
Comments
Member 11480976 27-Feb-15 4:26am    
What is _columnEnd over here in the code.
StackThanh 6-Mar-15 5:31am    
Sorry for the delay!
It is the last column that contains data in excel file

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900