Kastamonolu Posted December 10, 2018 Share Posted December 10, 2018 C# Excelde ki verileri datagridview'e kopyalama da bekletme Merhabalar, Yazdığım bir tane program var bu program excelde kopyaladığımız verileri datagridview'e yapıştırması lazım aşağıda atacağım kod yapıştırıyor ancak 50-100 arasındaki verileri anında ekliyor diğer yani büyük verileri 10000-20000 gibi verileri eklerken program "Yanıt Vermiyor" durumuna düşüyor. Fakat 3-4 dk sonra program düzeliyor ve verileri yapıştırmış oluyor. Bu bekletme olayını neden yapıyor veya nasıl çözebilirim? Bana bir yol önerirmisiniz. try { IDataObject obj = Clipboard.GetDataObject(); string s = Clipboard.GetText(); string[] lines = s.Split('\n'); int iFail = 0; bool headerSelected = false; if (dataGridView1.CurrentRow != null) { headerSelected = dataGridView1.CurrentRow.Selected; } int iCol = dataGridView1.ColumnCount - 1, iRow = dataGridView1.RowCount - 1; foreach (DataGridViewCell cell in dataGridView1.SelectedCells) { if (cell.ColumnIndex < iCol || cell.RowIndex < iRow) { iCol = cell.ColumnIndex; iRow = cell.RowIndex; } } foreach (string line in lines) { if (line.Length > 0) { if (iRow < dataGridView1.RowCount) { string[] sCells = line.Split('\t'); int offset = 0; for (int i = 0; (headerSelected ? i + 1 : i) < sCells.GetLength(0); ++i) { if (iCol + i < dataGridView1.ColumnCount) { while (!dataGridView1[iCol + i + offset, iRow].Visible && iCol + i + offset + 1 < dataGridView1.ColumnCount) { offset++; } if (dataGridView1[iCol + i + offset, iRow].Visible) { try { dataGridView1.CurrentCell = dataGridView1[iCol + i + offset, iRow]; } catch { ; } if (!dataGridView1.CurrentCell.ReadOnly) { string value = headerSelected ? sCells[i + 1] : sCells[i]; if (dataGridView1.CurrentCell.Value == null || dataGridView1.CurrentCell.Value.ToString() != value) { dataGridView1.BeginEdit(true); if (dataGridView1.EditingControl != null) { dataGridView1.EditingControl.Text = value; } else { dataGridView1.CurrentCell.Value = Convert.ChangeType(sCells[i], dataGridView1.CurrentCell.ValueType); } dataGridView1.NotifyCurrentCellDirty(true); dataGridView1.EndEdit(); } } else { iFail++; } } else { iFail++; } } } iRow++; } } else { break; } if (iFail > 0) { MessageBox.Show(string.Format("{0} güncellemeleri " + " yalnızca sütun ayarını okumak için başarısız oldu ", iFail)); } } } catch (FormatException) { MessageBox.Show("Yapıştırdığınız veriler hücrenin yanlış biçimindedir.", "Hata Penceresi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted February 23, 2019 Editor Share Posted February 23, 2019 Please register to see this content. Bu faydalı olacaktır. Quote Link to comment Share on other sites More sharing options...
hadibeolsun Posted February 23, 2019 Share Posted February 23, 2019 (edited) 1 verinin Exceldeki satırlara yüklenmesi için threading değeri ile 10000-20000 gibi verilerin yüklenmesi bir olabilir mi? Yaptığın işlemin Ram deki tutma oranına göre değişir. Çok yüksek kapasitede Ramlerin varsa 3-4 dk daha aza indirebilirsin. Unutma ki Satır ve Sütun olarak tek tek kopyalıyor excele bir anda kopyalanmıyor. Büyük projelerde SQL Server'ın Full-Text Semantic özelliği, SQL Full text ve Filter Daemon Launcher i SQL Server Browser özelliğini Aktif çalışır durumda bırakınız. Ya ilk 100 kaydı listeleyip excele attıracaksın sonra ikinci 100 kaydı excele yollayacaksın. Yada en güzeli CrystalReport üzerinde listeleme yapıp oradan Excele çekmek. Edited February 23, 2019 by hadibeolsun Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.