开发者

How can i remove null or empty whole rows using string.IsNullOrEmpty method?

i need your help to remove null and empty values in DataTable. My Excel table 4678 rows but returning rows more than 1000000 i need to remove empty or null ... Also MY COLUMNS COUNT 60!!! :( please help me

 foreach (var sheet in Sheets)
            {
                dbCommand = new OleDbCommand("select * From[" + sheet + "$]", excelConnection);
                System.Threading.Thread.Sleep(1000);
                this.Invoke((MethodInvoker)delegate
                {
                    listBox1.Items.Add("Tablo ismi: " + sheet.ToUpper(CultureInfo.InvariantCulture) + " Tablo Satır Sayısı: "+ dSet.Tables[sheet].Rows[0][0].ToString());
                });
                dataAdapter = new OleDbDataAdapter(dbCommand);
                dTable = new DataTable();
                dataAdapter.Fill(dTable);
                dTable.TableName = sheet.ToUpper(CultureInfo.InvariantCulture);;
                bool isEmpty = true;

                for (int i = 0; i < dTable.Rows.Count; i++)
                {
                    isEmpty = true;
                    for (int j = 0; j < dTabl开发者_StackOverflow中文版e.Columns.Count; j++)
                    {

                        if (string.IsNullOrEmpty(dTable.Rows[i][j].ToString()) == false)
                        {

                            isEmpty = false;
                            break;
                        }
                    }
                    if (isEmpty == true)
                    {
                        dTable.Rows.RemoveAt(i);
                        i--;
                    }
                }
                ArrangedDataList(dTable);


Excel remembers the last "visible/edited" cell. What you need to do is select cell A1, delete all the blank columns and rows, make sure cell A1 is still selected, save the workbook, then immediately exit Excel.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜