C# Excel’e Aktarma ( Excel Kurulu Olmadan )
10 Şubat 2020 / 13:39
Burak
Herkese merhabalar,
Bugünki yazımızda bilgisayarınızda Excel kurulu olmadan Excel’e aktarma ve Excel oluşturmayı anlatıcam. Öncelikle burada OpenOffice (Epplus ) dll indiriyoruz.
1.Adım kütüphanemizi yüklüyoruz.
1 2 |
using OfficeOpenXml; using System.IO; |
2.Adım daha sonra herhangi event’a aşağıdaki kodları yazmanız yeterlidir.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
using (ExcelPackage excelPackage = new ExcelPackage()) { //Set some properties of the Excel document excelPackage.Workbook.Properties.Author = "VDWWD"; excelPackage.Workbook.Properties.Title = "Title of Document"; excelPackage.Workbook.Properties.Subject = "EPPlus demo export data"; excelPackage.Workbook.Properties.Created = DateTime.Now; //Create the WorkSheet ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Sheet 1"); //Add some text to cell A1 worksheet.Cells["A1"].Value = "My first EPPlus spreadsheet!"; worksheet.Column(1).Style.WrapText = true; //You could also use [line, column] notation: worksheet.Cells[1, 2].Value = "This is cell B1!"; //Save your file FileInfo fi = new FileInfo(@"File.xlsx"); excelPackage.SaveAs(fi); } |
Satır rengini değiştirmek için
1 |
worksheet.Row(4).Style.Font.Color.SetColor(Color.Red); |
Sütun genişliğini değiştirmek için
1 |
worksheet.Column(1).Width = 12; |
Satır arkaplanını değiştirme için
1 2 |
sheet.Cells["A2:G2"].Style.Fill.PatternType = ExcelFillStyle.Solid; sheet.Cells["A2:G2"].Style.Fill.BackgroundColor.SetColor(Color.Red); |
Eğer dosyayı direk download etmek isterseniz aşağıdaki kodu kullanabilirsiniz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
using (ExcelPackage excelPackage = new ExcelPackage()) { //Set some properties of the Excel document excelPackage.Workbook.Properties.Author = "VDWWD"; excelPackage.Workbook.Properties.Title = "Title of Document"; excelPackage.Workbook.Properties.Subject = "EPPlus demo export data"; excelPackage.Workbook.Properties.Created = DateTime.Now; //Create the WorkSheet ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.Add("Sheet 1"); //Add some text to cell A1 worksheet.Cells["A1"].Value = "My first EPPlus spreadsheet!"; worksheet.Column(1).Style.WrapText = true; //You could also use [line, column] notation: worksheet.Cells[1, 2].Value = "This is cell B1!"; using (var memoryStream = new MemoryStream()) { Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AddHeader("content-disposition", "attachment; filename=dosya.xlsx"); excelPackage.SaveAs(memoryStream); memoryStream.WriteTo(Response.OutputStream); Response.Flush(); Response.End(); } } |
Etiketler: c# excel kurulu olmadan excel'e aktarma, c# excel'e aktarma, c# ile excel oluşturma, epplus examples, epplus ile excel aktarma, epplus kullanımı
Bu Yazılarıda Okuyabilirsiniz...
Bir cevap yazın