Removing empty rows in excel using C# -


i want remove empty rows @ end of program exection. in details inserting results after calculation using c# in predefined excel sheets. @ end need delete/remove empty rows programatically. 1 suggest solution. code little big unable include here. understanding giving input , output view of excel. in below output excel rows d , e having empty row want remove programatically without mentioning range.

input excel /pre defined excel files

a   1   2   3   4 b c d e 

output excel

a   1   2   3   4 b   abc cde nac 123 c   cdf fed x2  123 d e 

you can using range object. assume here using excel interop.

let have book open, set range delete it should this

applicationclass excel = new applicationclass(); //...  microsoft.office.interop.excel.range cel = (range)excel.cells[rowindex, columnindex]; cel.delete(); 

you can try using:

for(int = 1; <=20; i++) {    excelrange = (excel.range)excelworksheet.cells[i, 1];    if (!string.isnullorempty(excelrange.text.tostring()))    {        ((range)excelworksheet.rows[i]).delete(excelrange);    } } 

check out link below

https://social.msdn.microsoft.com/forums/office/en-us/469fdf10-35cc-46b2-a875-7b974deb5659/how-to-delete-all-empty-rows-from-a-excel-sheet-using-microsoftofficeinteropexcel?forum=exceldev

and

https://stackoverflow.com/a/9952004/4373895 here "something" null value.

hope helps.


Comments