Anarchosa Posted June 25, 2019 Share Posted June 25, 2019 Excel.Application excel = new Excel.Application();excel.Visible = true;object Missing = Type.Missing;Workbook workbook = excel.Workbooks.Add(Missing);Worksheet sheet1 = (Worksheet)workbook.Sheets[1];int baslamakolonu = 1;int baslamasatiri = 1;//label4 e gelen veri sayısı 2 olduğundan sadece onları ekliyor evet ben buldu mgalibafor (int i = 0; i < giden.Columns.Count; i++){excel.Cells[baslamasatiri, baslamakolonu + i].Value = giden.Columns.HeaderText;excel.Cells[baslamasatiri, baslamakolonu + i].Font.Color = System.Drawing.Color.Black; //Yazı Rengiexcel.Cells[baslamasatiri, baslamakolonu + i].Interior.Color = System.Drawing.Color.LightGoldenrodYellow; //Arka Plan Rengiexcel.Cells[baslamasatiri, baslamakolonu + i].Font.Bold = true; //Yazı Boldexcel.Cells[baslamasatiri, baslamakolonu + i].Font.Size = 9; //Yazı Sizeexcel.Cells[baslamasatiri, baslamakolonu + i].ColumnWidth = 18; //Colon Genişliğiexcel.Cells[baslamasatiri, baslamakolonu + i].Font.Name = "Arial";}//Heade Doldururfor (int j = 0; j < giden.Columns.Count; j++){Range myRange = (Range)sheet1.Cells[baslamasatiri, baslamakolonu + j];myRange.Value2 = giden.Columns[j].HeaderText;}//Header Doldurur Sonfor (int i = 1; i < giden.Rows.Count + 1; i++){for (int j = 0; j < giden.Columns.Count; j++){Range myRange = (Range)sheet1.Cells[baslamasatiri + i, baslamakolonu + j];myRange.Value2 = giden[j, i - 1].Value == null ? "" : giden[j, i - 1].Value;myRange.Select();//eski projede çalışır halini açayımmı ? 1 saniye}string satirdurumu = giden[3, i - 1].Value.ToString();if (satirdurumu == "DEPREM BÖLGESİ"){excel.Cells[i + 1, 4].Interior.Color = System.Drawing.Color.Red; //Arka Plan Rengiexcel.Cells[i + 1, 4].Font.Color = System.Drawing.Color.White; //Yazı Rengiexcel.Cells[i + 1, 4].Font.Bold = true; //Yazı Bold}else if (satirdurumu == "GÜVENLİ BÖLGE"){excel.Cells[i + 1, 4].Interior.Color = System.Drawing.Color.Green; //Arka Plan Rengiexcel.Cells[i + 1, 4].Font.Color = System.Drawing.Color.White; //Yazı Rengiexcel.Cells[i + 1, 4].Font.Bold = true; //Yazı Bold}} Excel.Application excel = new Excel.Application(); excel.Visible = true; object Missing = Type.Missing; Workbook workbook = excel.Workbooks.Add(Missing); Worksheet sheet1 = (Worksheet)workbook.Sheets[1]; int baslamakolonu = 1; int baslamasatiri = 1;//label4 e gelen veri sayısı 2 olduğundan sadece onları ekliyor evet ben buldu mgaliba for (int i = 0; i < giden.Columns.Count; i++) { excel.Cells[baslamasatiri, baslamakolonu + i].Value = giden.Columns[i].HeaderText; excel.Cells[baslamasatiri, baslamakolonu + i].Font.Color = System.Drawing.Color.Black; //Yazı Rengi excel.Cells[baslamasatiri, baslamakolonu + i].Interior.Color = System.Drawing.Color.LightGoldenrodYellow; //Arka Plan Rengi excel.Cells[baslamasatiri, baslamakolonu + i].Font.Bold = true; //Yazı Bold excel.Cells[baslamasatiri, baslamakolonu + i].Font.Size = 9; //Yazı Size excel.Cells[baslamasatiri, baslamakolonu + i].ColumnWidth = 18; //Colon Genişliği excel.Cells[baslamasatiri, baslamakolonu + i].Font.Name = "Arial"; } //Heade Doldurur for (int j = 0; j < giden.Columns.Count; j++) { Range myRange = (Range)sheet1.Cells[baslamasatiri, baslamakolonu + j]; myRange.Value2 = giden.Columns[j].HeaderText; } //Header Doldurur Son for (int i = 1; i < giden.Rows.Count + 1; i++) { for (int j = 0; j < giden.Columns.Count; j++) { Range myRange = (Range)sheet1.Cells[baslamasatiri + i, baslamakolonu + j]; myRange.Value2 = giden[j, i - 1].Value == null ? "" : giden[j, i - 1].Value; myRange.Select(); //eski projede çalışır halini açayımmı ? 1 saniye } string satirdurumu = giden[3, i - 1].Value.ToString(); if (satirdurumu == "DEPREM BÖLGESİ") { excel.Cells[i + 1, 4].Interior.Color = System.Drawing.Color.Red; //Arka Plan Rengi excel.Cells[i + 1, 4].Font.Color = System.Drawing.Color.White; //Yazı Rengi excel.Cells[i + 1, 4].Font.Bold = true; //Yazı Bold } else if (satirdurumu == "GÜVENLİ BÖLGE") { excel.Cells[i + 1, 4].Interior.Color = System.Drawing.Color.Green; //Arka Plan Rengi excel.Cells[i + 1, 4].Font.Color = System.Drawing.Color.White; //Yazı Rengi excel.Cells[i + 1, 4].Font.Bold = true; //Yazı Bold } } System.Runtime.InteropServices.COMException: 'Arama aranan tarafından kabul edilmedi. (HRESULT özel durum döndürdü: 0x80010001 (RPC_E_CALL_REJECTED))' Hatası Alıorum. Yardımcı Olurmusunuz Quote Link to comment Share on other sites More sharing options...
hadibeolsun Posted June 25, 2019 Share Posted June 25, 2019 (edited) Tasarımı şöyle yap : Please register to see this content. Aç butonunun Click Eventına OpenFileDialog Ac = new OpenFileDialog(); Ac.Filter = "Excel 2003(*.xls)|*.xls| Excel 2007(*.xlsx)|*.xlsx"; if (Ac.ShowDialog() == DialogResult.OK) { KariyerMuhasebeSeti.Classlar.ExcelIslemleri Excel = new KariyerMuhasebeSeti.Classlar.ExcelIslemleri(); DataTable Veriler = Excel.Veriler(Ac.FileName); Liste.DataSource = Veriler; this.Cursor = Cursors.Default; foreach (Control Nesne in groupBox1.Controls) { if (Nesne is DevExpress.XtraEditors.ComboBoxEdit) { SutunAl((DevExpress.XtraEditors.ComboBoxEdit)Nesne); } } } İlgili Sütunları alan kod void SutunAl(DevExpress.XtraEditors.ComboBoxEdit Nesne) { DevExpress.XtraEditors.Controls.ComboBoxItemCollection Sutunlar = Nesne.Properties.Items; Sutunlar.Clear(); Sutunlar.BeginUpdate(); Sutunlar.Add(""); for (int i = 0; i < gridView1.Columns.Count; i++) { Sutunlar.Add(gridView1.Columns[i].FieldName.ToString()); } Nesne.SelectedIndex = 0; Sutunlar.EndUpdate(); } İçeri aktar Butonunun Click Eventına void IceriAktar() { Classlar.clsStokKod1 StokKod1 = new Classlar.clsStokKod1(); Classlar.clsStokKod2 StokKod2 = new Classlar.clsStokKod2(); Classlar.clsStokKod3 StokKod3 = new Classlar.clsStokKod3(); Classlar.clsStokKod4 StokKod4 = new Classlar.clsStokKod4(); string StokKodu, StokAdi, Birim, Barkod, AlisKdv, SatisKdv, AlisFiyati1, AlisFiyati2, SatisFiyati1, SatisFiyati2, Kod1, Kod2, Kod3, Kod4, FiiliStok, NegatifStok, StokAlarmi, Statusu; this.Cursor = Cursors.WaitCursor; for (int i = 0; i < gridView1.RowCount -1; i++) //Listedeki Kayıt Sayısı kadar döndük... { StokKodu = DegerAl(comStokKodu, i); StokAdi = DegerAl(comStokAdi, i); Kod1 = DegerAl(comKod1, i); Kod2 = DegerAl(comKod2, i); Kod3 = DegerAl(comKod3, i); Kod4 = DegerAl(comKod4, i); Birim = DegerAl(comBirim, i); Barkod = DegerAl(comBarkod, i); AlisKdv = DegerAl(comAlisKdv, i); SatisKdv = DegerAl(comSatisKdv, i); AlisFiyati1 = DegerAl(comAlisFiyat1, i); AlisFiyati2 = DegerAl(comAlisFiyat2, i); SatisFiyati1 = DegerAl(comSatisFiyat1, i); SatisFiyati2 = DegerAl(comSatisFiyat2, i); FiiliStok = DegerAl(comFiiliStok, i); NegatifStok = DegerAl(comNegatifStok, i); StokAlarmi = DegerAl(comStokAlarmi, i); Statusu = DegerAl(comStatusu, i); string KullaniciID = KariyerMuhasebeSeti.AnaForm.frmAnaForm.UserId; Stok.Ekle(StokKodu, StokAdi, Birim, Barkod, AlisKdv, SatisKdv, AlisFiyati1, AlisFiyati2, SatisFiyati1, SatisFiyati2, StokKod1.IdAl(Kod1, true, KullaniciID), StokKod2.IdAl(Kod2, true, KullaniciID), StokKod3.IdAl(Kod3, true, KullaniciID), StokKod4.IdAl(Kod4, true, KullaniciID), FiiliStok, NegatifStok, StokAlarmi, Statusu, KullaniciID); } this.Cursor = Cursors.Default; Mesajlar.Bilgi("Toplu Stok Açma İşlemi Başarılı Bir Şekilde Kaydedilmiştir."); } İlgili Değeri almak için Fonksiyon string DegerAl(DevExpress.XtraEditors.ComboBoxEdit Nesne, int SatirId) { string Deger = ""; if (Nesne.SelectedIndex > 0) { Deger = gridView1.GetRowCellValue(SatirId, Nesne.SelectedItem.ToString()).ToString(); } return Deger; } public DataTable Veriler(string Yol) { string BaglantiStringi = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Yol + "; Extended Properties='Excel 8.0;';"; OleDbConnection baglanti = new OleDbConnection(BaglantiStringi); baglanti.Open(); OleDbDataAdapter Adapter = new OleDbDataAdapter("SELECT * FROM [Sayfa1$A:Z]", baglanti); DataTable Veriler = new DataTable(); Adapter.Fill(Veriler); return Veriler; } Bu yukarıdaki kod da Exceldeki veriyi çeker. Excel'e aktarma butonunun Click Eventına Excel.Application excel = new Excel.Application(); excel.Visible = true; object Missing = Type.Missing; Workbook workbook = excel.Workbooks.Add(Missing); Worksheet sheet1 = (Worksheet)workbook.Sheets[1]; int StartCol = 1; int StartRow = 1; for (int j = 0; j < dataGridView1.Columns.Count; j++) { Range myRange = (Range)sheet1.Cells[StartRow, StartCol + j]; myRange.Value2 = dataGridView1.Columns[j].HeaderText; } StartRow++; for (int i = 0; i < dataGridView1.Rows.Count; i++) { for (int j = 0; j < dataGridView1.Columns.Count; j++) { Range myRange = (Range)sheet1.Cells[StartRow + i, StartCol + j]; myRange.Value2 = dataGridView1[j, i].Value == null ? "" : dataGridView1[j, i].Value; myRange.Select(); } } C# ile Ön Muhasebe Eğitim DVD'si istersen 100 TL den satıyorum. 2012 yılında aldığım eğitim setidir http://www.kariyeregitimseti.com/csharp_ile_on_muhasebe_programi_projesi_egitim_seti_detay.html Edited June 25, 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.