如何在C#Application中使用OLEDB从Excel工作表中删除所有空行 [英] How to delete all empty rows from a excel sheet using OLEDB in C# Application

查看:590
本文介绍了如何在C#Application中使用OLEDB从Excel工作表中删除所有空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的EveryBody!

我的英语不好。

我正在编写一个应用程序,使用OLEDB将多个excel文件合并到一个文件中,该程序运行正常。

但是当excel文件有多个空行时遇到问题,我不知道如何删除空行?

希望得到大家的帮助!

谢谢!

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!

推荐答案

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



然后我会检查该行是否为空然后使用例如作为起点。





祝你好运。
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.


你好



使用MS Excel(xls / xlsx)使用MDAC和Oledb [ ^ ]





好​​运
Hello

Working with MS Excel(xls / xlsx) Using MDAC and Oledb[^]


Good Luck


亲爱的Slacker007,CB夏尔马!

首先,谢谢你的帮助2.

你们两个人的帮助对我很有帮助。

感谢您的帮助,我的问题解决了。

代码演示:



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:

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--;
         }
   }


这篇关于如何在C#Application中使用OLEDB从Excel工作表中删除所有空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆