C# WINDOWS UYGULAMASI HAZIRLAMA ADO.NET SUNU5 –EXCELE BİLGİ AKTARMA SAVA Ş TUNÇER
EXCEL VER İ AKTARMA CS KOMUTLARI private void button9_Click(object sender, EventArgs e) { SqlCommand komut = new SqlCommand("SELECT *FROM kalanilac ", baglan); SqlDataAdapter da = new SqlDataAdapter(komut); DataSet ds = new DataSet(); da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; baglan.Close(); textBox4.Clear(); Microsoft.Office.Interop.Excel.Application uygulama = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook kitap = uygulama.Workbooks.Add(true); Microsoft.Office.Interop.Excel.Worksheet sayfa = (Microsoft.Office.Interop.Excel.Worksheet)uygulama.ActiveSheet; uygulama.Visible = true; int rowIndex = 1; int colIndex = 0;
foreach (DataColumn col in ds.Tables[0].Columns) { colIndex++; sayfa.Cells[1, colIndex] = col.ColumnName; } foreach (DataRow row in ds.Tables[0].Rows) { rowIndex++; colIndex = 0; foreach (DataColumn col in ds.Tables[0].Columns) { colIndex++; sayfa.Cells[rowIndex, colIndex] = row[col.ColumnName].ToString(); } button9.Visible = false; }