How to Create an Excel File in C# (.NET Tutorial)
IronXL, güçlü bir C# ve .NET Excel kütüphanesi olup, Microsoft Office veya Interop bağımlılıkları olmadan programatik olarak XLSX elektronik tabloları oluşturmanıza, okumanıza ve düzenlemenize olanak tanır. .NET 8, .NET 9, .NET Core, .NET Framework'ü destekler ve Windows, Linux, macOS, Azure ve AWS üzerinde çalışır.
Bu öğretici, hücre değerlerini ayarlama, biçimlendirme uygulama, formüller ekleme ve XLSX, CSV ve daha fazlasına dışa aktarma gibi tam bir Excel çalışma kitabı oluşturmayı adım adım kod örnekleri ile anlatır.
Hızlı Başlangıç: Bir Excel Dosyası Oluşturun
IronXL kullanarak kısa sürede yeni bir Excel dosyası oluşturun — sadece bir format seçin, bir sayfa ekleyin, herhangi bir hücre değerini ayarlayın ve kaydedin. Bu, sezgisel API çağrılarıyla ve sıfır interop karmaşasıyla XLSX dosyaları oluşturmanın en hızlı yoludur.
-
IronXL aşağıdaki NuGet Paket Yöneticisi ile yükleyin
PM > Install-Package IronXL.Excel -
Bu kod parçacığını kopyalayın ve çalıştırın.
WorkBook book = IronXl.WorkBook.Create(IronXl.ExcelFileFormat.XLSX); book.CreateWorkSheet("Sheet1")["A1"].Value = "Hello World"; book.SaveAs("MyFile.xlsx"); -
Canlı ortamınızda test için dağıtım yapın
Ücretsiz deneme ile bugün projenizde IronXL kullanmaya başlayın
Asgari İş Akışı (5 adım)
- IronXL C# kütüphanesini indirin ve kurun
- .NET projenizi ayarlayın
WorkbookveWorksheetoluştur- Hücre değerlerini, biçimlendirmelerini ve formüllerini ayarlayın
- Excel dosyanızı kaydedin
IronXL nedir ve Excel Dosyası Oluşturmak İçin Neden Kullanılır?
IronXL, .NET içinde olağanüstü performansla Excel elektronik tablo dosyalarını okumanız, düzenlemeniz ve oluşturmanız için sezgisel bir C# & VB Excel API'sidir. Geleneksel yaklaşımların aksine, dağıtımı daha basit ve daha güvenilir hale getiren Microsoft Office yüklemesine veya Excel Interop kullanımına gerek yoktur.
IronXL tamamen .NET 9, .NET 8, .NET Core, .NET Framework, Xamarin, Mobil, Linux, macOS ve Azure ortamlarını tam olarak destekler.
IronXL Özellikleri
- .NET geliştirme ekibimizden doğrudan insan desteği
- Microsoft Visual Studio ile hızlı yükleme
- Geliştirme için ÜCRETSİZ. $999'den alınan lisanslar
Excel Dosyasını Hızla Nasıl Oluşturup Kaydedebilirim?
IronXL'yi NuGet üzerinden yükleyin veya DLL dosyasını doğrudan indirin. WorkBook sınıfı, tüm Excel işlemleri için giriş noktanızdır; WorkSheet sınıfı ise tek tek sayfaları işlemek için yöntemler sağlar — adım adım kılavuzun tamamı aşağıdaki 1. Adımda başlar.
How Do I Install the IronXL C# Library?
IronXL'yi Visual Studio'da NuGet Paket Yöneticisi aracılığıyla yükleyin veya Paket Yöneticisi Konsolunu kullanın:
Install-Package IronXL.Excel
Proje menüsünden veya Çözüm Gezgini'nde projenize sağ tıklayarak NuGet Paket Yöneticisi'ne erişin.

Şekil 3 - Proje menüsü üzerinden NuGet Paket Yöneticisi'ne erişin

Şekil 4 - Çözüm Gezgini'nde sağ tıklama bağlam menüsü
Paket listesinde IronXl.Excel öğesini bulun ve Yükle'yi tıklayın.

Şekil 5 - IronXl.Excel'i NuGet Paket Yöneticisi aracılığıyla yüklerken
Alternatif olarak, IronXL DLL dosyasını doğrudan indirin ve Solution Explorer > References > Browse for IronXL.dll yolunu kullanarak projenize referans olarak ekleyin.

Şekil 6 - Resmi web sitesinden IronXL kütüphanesini indirin
{i:(IronXL, Microsoft Office veya Excel Interop kurulumuna ihtiyaç duymaz — Windows, Linux, macOS ve bulut ortamlarını içeren her türlü .NET destekli platformda çalışır.)}
.NET Projeyi Nasıl Ayarlayabilirim?
IronXL her türlü .NET proje türüyle çalışır — konsol uygulamaları, ASP.NET web uygulamaları, API'ler veya masaüstü araçları. Aşağıdaki örnek bir ASP.NET Web Uygulaması kullanır, ancak süreç tüm proje şablonları arasında aynıdır.
Bir ASP.NET web sitesi oluşturmak için bu adımları izleyin:
- Visual Studio'yu açın
- Dosya > Yeni Proje'ye tıklayın
- Proje türü listesinde Visual C# altında Web'i seçin
-
ASP.NET Web Uygulaması'nı seçin

Şekil 1 – Create new ASP.NET project
- Tamam'a tıklayın
-
Web Forms şablonunu seçin

Şekil 2 – Select Web Forms template
- OK'a tıklayın
Projeniz hazır olduğunda, programatik olarak Excel dosyaları oluşturmak için IronXL'yi kurun.
How Do I Create an Excel Workbook in C#?
IronXL ile yeni bir Excel çalışma kitabı oluşturmak sadece bir satır kod gerektirir:
using IronXL;
// Create workbook with XLSX format (recommended for modern Excel)
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
// Alternative: Create legacy XLS format for older Excel versions
WorkBook legacyWorkbook = WorkBook.Create(ExcelFileFormat.XLS);
using IronXL;
// Create workbook with XLSX format (recommended for modern Excel)
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
// Alternative: Create legacy XLS format for older Excel versions
WorkBook legacyWorkbook = WorkBook.Create(ExcelFileFormat.XLS);
Imports IronXL
' Create workbook with XLSX format (recommended for modern Excel)
Private workbook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
' Alternative: Create legacy XLS format for older Excel versions
Private legacyWorkbook As WorkBook = WorkBook.Create(ExcelFileFormat.XLS)
Create yöntemi hem XLS (Excel 97-2003) hem de XLSX (Excel 2007+) formatlarını destekler. Daha iyi performans ve daha küçük dosya boyutları için XLSX önerilir.
- XLSX: Tüm modern Excel sürümleri (2007+) için önerilir — daha küçük dosyalar, daha iyi performans
- XLS: Excel 97–2003 ile uyumlu eski format
Çalışma Kitabıma Nasıl Çalışma Sayfası Eklerim?
Çalışma sayfası eklemek basittir:
// Create a worksheet with custom name for budget tracking
WorkSheet budgetSheet = workbook.CreateWorkSheet("2020 Budget");
// Add multiple worksheets for different purposes
WorkSheet salesSheet = workbook.CreateWorkSheet("Sales Data");
WorkSheet inventorySheet = workbook.CreateWorkSheet("Inventory");
// Access existing worksheet by name
WorkSheet existingSheet = workbook.GetWorkSheet("2020 Budget");
// Create a worksheet with custom name for budget tracking
WorkSheet budgetSheet = workbook.CreateWorkSheet("2020 Budget");
// Add multiple worksheets for different purposes
WorkSheet salesSheet = workbook.CreateWorkSheet("Sales Data");
WorkSheet inventorySheet = workbook.CreateWorkSheet("Inventory");
// Access existing worksheet by name
WorkSheet existingSheet = workbook.GetWorkSheet("2020 Budget");
' Create a worksheet with custom name for budget tracking
Dim budgetSheet As WorkSheet = workbook.CreateWorkSheet("2020 Budget")
' Add multiple worksheets for different purposes
Dim salesSheet As WorkSheet = workbook.CreateWorkSheet("Sales Data")
Dim inventorySheet As WorkSheet = workbook.CreateWorkSheet("Inventory")
' Access existing worksheet by name
Dim existingSheet As WorkSheet = workbook.GetWorkSheet("2020 Budget")
Bir çalışma kitabı bir veya daha fazla çalışma sayfası içerir. Her çalışma sayfası, hücrelerin kesiştiği satır ve sütunlardan oluşur. Çalışma kitabınıza yeni sayfalar eklemek için CreateWorkSheet yöntemini kullanın.
WorkBook.CreateWorkSheet(String): Belirtilen sekme adıyla yeni bir sayfa eklerWorkSheet: Adına göre mevcut bir sayfayı alır- Sayfa adları bir çalışma kitabında benzersiz olmalıdır
Excel'de Hücre Değerlerini Nasıl Ayarlarım?
Hücre Değerlerini Manüel Olarak Nasıl Ayarlayabilirim?
Tek tek hücre değerlerini ayarlamak, Excel benzeri sezgisel bir sözdizimi kullanır:
// Set month names in first row for annual budget spreadsheet
workSheet["A1"].Value = "January";
workSheet["B1"].Value = "February";
workSheet["C1"].Value = "March";
workSheet["D1"].Value = "April";
workSheet["E1"].Value = "May";
workSheet["F1"].Value = "June";
workSheet["G1"].Value = "July";
workSheet["H1"].Value = "August";
workSheet["I1"].Value = "September";
workSheet["J1"].Value = "October";
workSheet["K1"].Value = "November";
workSheet["L1"].Value = "December";
// Set different data types - IronXL handles conversion automatically
workSheet["A2"].Value = 1500.50m; // Decimal for currency
workSheet["A3"].Value = DateTime.Now; // Date values
workSheet["A4"].Value = true; // Boolean values
// Set month names in first row for annual budget spreadsheet
workSheet["A1"].Value = "January";
workSheet["B1"].Value = "February";
workSheet["C1"].Value = "March";
workSheet["D1"].Value = "April";
workSheet["E1"].Value = "May";
workSheet["F1"].Value = "June";
workSheet["G1"].Value = "July";
workSheet["H1"].Value = "August";
workSheet["I1"].Value = "September";
workSheet["J1"].Value = "October";
workSheet["K1"].Value = "November";
workSheet["L1"].Value = "December";
// Set different data types - IronXL handles conversion automatically
workSheet["A2"].Value = 1500.50m; // Decimal for currency
workSheet["A3"].Value = DateTime.Now; // Date values
workSheet["A4"].Value = true; // Boolean values
' Set month names in first row for annual budget spreadsheet
workSheet("A1").Value = "January"
workSheet("B1").Value = "February"
workSheet("C1").Value = "March"
workSheet("D1").Value = "April"
workSheet("E1").Value = "May"
workSheet("F1").Value = "June"
workSheet("G1").Value = "July"
workSheet("H1").Value = "August"
workSheet("I1").Value = "September"
workSheet("J1").Value = "October"
workSheet("K1").Value = "November"
workSheet("L1").Value = "December"
' Set different data types - IronXL handles conversion automatically
workSheet("A2").Value = 1500.50D ' Decimal for currency
workSheet("A3").Value = DateTime.Now ' Date values
workSheet("A4").Value = True ' Boolean values
Value özelliği, dizeler, sayılar, tarihler ve boole değerleri dahil olmak üzere çeşitli veri türlerini kabul eder. IronXL, veri türüne göre hücreleri otomatik olarak biçimlendirir.
Hücre Değerlerini Dinamik Olarak Nasıl Ayarlayabilirim?
Dinamik değer ayarlama, veri odaklı uygulamalar için mükemmeldir:
// Initialize random number generator for sample data
Random r = new Random();
// Populate cells with random budget data for each month
for (int i = 2; i <= 11; i++)
{
// Set different budget categories with increasing ranges
workSheet[$"A{i}"].Value = r.Next(1, 1000); // Office Supplies
workSheet[$"B{i}"].Value = r.Next(1000, 2000); // Utilities
workSheet[$"C{i}"].Value = r.Next(2000, 3000); // Rent
workSheet[$"D{i}"].Value = r.Next(3000, 4000); // Salaries
workSheet[$"E{i}"].Value = r.Next(4000, 5000); // Marketing
workSheet[$"F{i}"].Value = r.Next(5000, 6000); // IT Services
workSheet[$"G{i}"].Value = r.Next(6000, 7000); // Travel
workSheet[$"H{i}"].Value = r.Next(7000, 8000); // Training
workSheet[$"I{i}"].Value = r.Next(8000, 9000); // Insurance
workSheet[$"J{i}"].Value = r.Next(9000, 10000); // Equipment
workSheet[$"K{i}"].Value = r.Next(10000, 11000); // Research
workSheet[$"L{i}"].Value = r.Next(11000, 12000); // Misc
}
// Alternative: Set range of cells with same value
workSheet["A13:L13"].Value = 0; // Initialize totals row
// Initialize random number generator for sample data
Random r = new Random();
// Populate cells with random budget data for each month
for (int i = 2; i <= 11; i++)
{
// Set different budget categories with increasing ranges
workSheet[$"A{i}"].Value = r.Next(1, 1000); // Office Supplies
workSheet[$"B{i}"].Value = r.Next(1000, 2000); // Utilities
workSheet[$"C{i}"].Value = r.Next(2000, 3000); // Rent
workSheet[$"D{i}"].Value = r.Next(3000, 4000); // Salaries
workSheet[$"E{i}"].Value = r.Next(4000, 5000); // Marketing
workSheet[$"F{i}"].Value = r.Next(5000, 6000); // IT Services
workSheet[$"G{i}"].Value = r.Next(6000, 7000); // Travel
workSheet[$"H{i}"].Value = r.Next(7000, 8000); // Training
workSheet[$"I{i}"].Value = r.Next(8000, 9000); // Insurance
workSheet[$"J{i}"].Value = r.Next(9000, 10000); // Equipment
workSheet[$"K{i}"].Value = r.Next(10000, 11000); // Research
workSheet[$"L{i}"].Value = r.Next(11000, 12000); // Misc
}
// Alternative: Set range of cells with same value
workSheet["A13:L13"].Value = 0; // Initialize totals row
' Initialize random number generator for sample data
Dim r As New Random()
' Populate cells with random budget data for each month
For i As Integer = 2 To 11
' Set different budget categories with increasing ranges
workSheet($"A{i}").Value = r.Next(1, 1000) ' Office Supplies
workSheet($"B{i}").Value = r.Next(1000, 2000) ' Utilities
workSheet($"C{i}").Value = r.Next(2000, 3000) ' Rent
workSheet($"D{i}").Value = r.Next(3000, 4000) ' Salaries
workSheet($"E{i}").Value = r.Next(4000, 5000) ' Marketing
workSheet($"F{i}").Value = r.Next(5000, 6000) ' IT Services
workSheet($"G{i}").Value = r.Next(6000, 7000) ' Travel
workSheet($"H{i}").Value = r.Next(7000, 8000) ' Training
workSheet($"I{i}").Value = r.Next(8000, 9000) ' Insurance
workSheet($"J{i}").Value = r.Next(9000, 10000) ' Equipment
workSheet($"K{i}").Value = r.Next(10000, 11000) ' Research
workSheet($"L{i}").Value = r.Next(11000, 12000) ' Misc
Next i
' Alternative: Set range of cells with same value
workSheet("A13:L13").Value = 0 ' Initialize totals row
Dize interpolasyonu ($"..."), hücrelere dinamik olarak kolayca başvurmayı sağlar. Item indeksleyici, hem tek tek hücreleri hem de aralıkları destekler.
Excel'e Veritabanından Nasıl Veri Yüklerim?
Veritabanlarından Excel'e veri yüklemek yaygın bir gereksinimdir:
using System.Data;
using System.Data.SqlClient;
using IronXL;
// Database connection setup for retrieving sales data
string connectionString = @"Data Source=ServerName;Initial Catalog=SalesDB;Integrated Security=true";
string query = "SELECT ProductName, Quantity, UnitPrice, TotalSales FROM MonthlySales";
// Create DataSet to hold query results
DataSet salesData = new DataSet();
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlDataAdapter adapter = new SqlDataAdapter(query, connection))
{
// Fill DataSet with sales information
adapter.Fill(salesData);
}
// Write headers for database columns
workSheet["A1"].Value = "Product Name";
workSheet["B1"].Value = "Quantity";
workSheet["C1"].Value = "Unit Price";
workSheet["D1"].Value = "Total Sales";
// Apply header formatting
workSheet["A1:D1"].Style.Font.Bold = true;
workSheet["A1:D1"].Style.SetBackgroundColor("#4472C4");
workSheet["A1:D1"].Style.Font.FontColor = "#FFFFFF";
// Populate Excel with database records
DataTable salesTable = salesData.Tables[0];
for (int row = 0; row < salesTable.Rows.Count; row++)
{
int excelRow = row + 2; // Start from row 2 (after headers)
workSheet[$"A{excelRow}"].Value = salesTable.Rows[row]["ProductName"].ToString();
workSheet[$"B{excelRow}"].Value = Convert.ToInt32(salesTable.Rows[row]["Quantity"]);
workSheet[$"C{excelRow}"].Value = Convert.ToDecimal(salesTable.Rows[row]["UnitPrice"]);
workSheet[$"D{excelRow}"].Value = Convert.ToDecimal(salesTable.Rows[row]["TotalSales"]);
// Format currency columns
workSheet[$"C{excelRow}"].FormatString = "$#,##0.00";
workSheet[$"D{excelRow}"].FormatString = "$#,##0.00";
}
// Add summary row with formulas
int summaryRow = salesTable.Rows.Count + 2;
workSheet[$"A{summaryRow}"].Value = "TOTAL";
workSheet[$"B{summaryRow}"].Formula = $"=SUM(B2:B{summaryRow-1})";
workSheet[$"D{summaryRow}"].Formula = $"=SUM(D2:D{summaryRow-1})";
using System.Data;
using System.Data.SqlClient;
using IronXL;
// Database connection setup for retrieving sales data
string connectionString = @"Data Source=ServerName;Initial Catalog=SalesDB;Integrated Security=true";
string query = "SELECT ProductName, Quantity, UnitPrice, TotalSales FROM MonthlySales";
// Create DataSet to hold query results
DataSet salesData = new DataSet();
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlDataAdapter adapter = new SqlDataAdapter(query, connection))
{
// Fill DataSet with sales information
adapter.Fill(salesData);
}
// Write headers for database columns
workSheet["A1"].Value = "Product Name";
workSheet["B1"].Value = "Quantity";
workSheet["C1"].Value = "Unit Price";
workSheet["D1"].Value = "Total Sales";
// Apply header formatting
workSheet["A1:D1"].Style.Font.Bold = true;
workSheet["A1:D1"].Style.SetBackgroundColor("#4472C4");
workSheet["A1:D1"].Style.Font.FontColor = "#FFFFFF";
// Populate Excel with database records
DataTable salesTable = salesData.Tables[0];
for (int row = 0; row < salesTable.Rows.Count; row++)
{
int excelRow = row + 2; // Start from row 2 (after headers)
workSheet[$"A{excelRow}"].Value = salesTable.Rows[row]["ProductName"].ToString();
workSheet[$"B{excelRow}"].Value = Convert.ToInt32(salesTable.Rows[row]["Quantity"]);
workSheet[$"C{excelRow}"].Value = Convert.ToDecimal(salesTable.Rows[row]["UnitPrice"]);
workSheet[$"D{excelRow}"].Value = Convert.ToDecimal(salesTable.Rows[row]["TotalSales"]);
// Format currency columns
workSheet[$"C{excelRow}"].FormatString = "$#,##0.00";
workSheet[$"D{excelRow}"].FormatString = "$#,##0.00";
}
// Add summary row with formulas
int summaryRow = salesTable.Rows.Count + 2;
workSheet[$"A{summaryRow}"].Value = "TOTAL";
workSheet[$"B{summaryRow}"].Formula = $"=SUM(B2:B{summaryRow-1})";
workSheet[$"D{summaryRow}"].Formula = $"=SUM(D2:D{summaryRow-1})";
Imports System.Data
Imports System.Data.SqlClient
Imports IronXL
' Database connection setup for retrieving sales data
Private connectionString As String = "Data Source=ServerName;Initial Catalog=SalesDB;Integrated Security=true"
Private query As String = "SELECT ProductName, Quantity, UnitPrice, TotalSales FROM MonthlySales"
' Create DataSet to hold query results
Private salesData As New DataSet()
Using connection As New SqlConnection(connectionString)
Using adapter As New SqlDataAdapter(query, connection)
' Fill DataSet with sales information
adapter.Fill(salesData)
End Using
End Using
' Write headers for database columns
workSheet("A1").Value = "Product Name"
workSheet("B1").Value = "Quantity"
workSheet("C1").Value = "Unit Price"
workSheet("D1").Value = "Total Sales"
' Apply header formatting
workSheet("A1:D1").Style.Font.Bold = True
workSheet("A1:D1").Style.SetBackgroundColor("#4472C4")
workSheet("A1:D1").Style.Font.FontColor = "#FFFFFF"
' Populate Excel with database records
Dim salesTable As DataTable = salesData.Tables(0)
For row As Integer = 0 To salesTable.Rows.Count - 1
Dim excelRow As Integer = row + 2 ' Start from row 2 (after headers)
workSheet($"A{excelRow}").Value = salesTable.Rows(row)("ProductName").ToString()
workSheet($"B{excelRow}").Value = Convert.ToInt32(salesTable.Rows(row)("Quantity"))
workSheet($"C{excelRow}").Value = Convert.ToDecimal(salesTable.Rows(row)("UnitPrice"))
workSheet($"D{excelRow}").Value = Convert.ToDecimal(salesTable.Rows(row)("TotalSales"))
' Format currency columns
workSheet($"C{excelRow}").FormatString = "$#,##0.00"
workSheet($"D{excelRow}").FormatString = "$#,##0.00"
Next row
' Add summary row with formulas
Dim summaryRow As Integer = salesTable.Rows.Count + 2
workSheet($"A{summaryRow}").Value = "TOTAL"
workSheet($"B{summaryRow}").Formula = $"=SUM(B2:B{summaryRow-1})"
workSheet($"D{summaryRow}").Formula = $"=SUM(D2:D{summaryRow-1})"
Bu örnek, veritabanlarından Excel verilerini okuma, biçimlendirme uygulama ve hesaplamalar için formüller kullanmayı gösterir. NumberFormat özelliği, tıpkı Excel'de olduğu gibi özel sayı biçimlendirmesine olanak tanır.
Excel Hücrelerine Nasıl Biçim Uygularım?
Excel'de Arka Plan Renklerini Nasıl Ayarlayabilirim?
Hücre stilleri, okunabilirliği ve görsel çekiciliği artırır:
// Set header row background to light gray using hex color
workSheet["A1:L1"].Style.SetBackgroundColor("#d3d3d3");
// Apply different colors for data categorization
workSheet["A2:A11"].Style.SetBackgroundColor("#E7F3FF"); // Light blue for January
workSheet["B2:B11"].Style.SetBackgroundColor("#FFF2CC"); // Light yellow for February
// Highlight important cells with bold colors
workSheet["L12"].Style.SetBackgroundColor("#FF0000"); // Red for totals
workSheet["L12"].Style.Font.FontColor = "#FFFFFF"; // White text
// Create alternating row colors for better readability
for (int row = 2; row <= 11; row++)
{
if (row % 2 == 0)
{
workSheet[$"A{row}:L{row}"].Style.SetBackgroundColor("#F2F2F2");
}
}
// Set header row background to light gray using hex color
workSheet["A1:L1"].Style.SetBackgroundColor("#d3d3d3");
// Apply different colors for data categorization
workSheet["A2:A11"].Style.SetBackgroundColor("#E7F3FF"); // Light blue for January
workSheet["B2:B11"].Style.SetBackgroundColor("#FFF2CC"); // Light yellow for February
// Highlight important cells with bold colors
workSheet["L12"].Style.SetBackgroundColor("#FF0000"); // Red for totals
workSheet["L12"].Style.Font.FontColor = "#FFFFFF"; // White text
// Create alternating row colors for better readability
for (int row = 2; row <= 11; row++)
{
if (row % 2 == 0)
{
workSheet[$"A{row}:L{row}"].Style.SetBackgroundColor("#F2F2F2");
}
}
' Set header row background to light gray using hex color
workSheet("A1:L1").Style.SetBackgroundColor("#d3d3d3")
' Apply different colors for data categorization
workSheet("A2:A11").Style.SetBackgroundColor("#E7F3FF") ' Light blue for January
workSheet("B2:B11").Style.SetBackgroundColor("#FFF2CC") ' Light yellow for February
' Highlight important cells with bold colors
workSheet("L12").Style.SetBackgroundColor("#FF0000") ' Red for totals
workSheet("L12").Style.Font.FontColor = "#FFFFFF" ' White text
' Create alternating row colors for better readability
For row As Integer = 2 To 11
If row Mod 2 = 0 Then
workSheet($"A{row}:L{row}").Style.SetBackgroundColor("#F2F2F2")
End If
Next row
SetBackgroundColor yöntemi onaltılık renk kodlarını kabul eder. Arka plan renklerini yazı tipleriyle birleştirerek profesyonel görünümlü elektronik tablolar oluşturun.
Excel'de Çerçeveler Nasıl Oluşturulur?
Çerçeveler, veri bölgelerini tanımlamaya ve yapıyı iyileştirmeye yardımcı olur:
using IronXL;
using IronXl.Styles;
// Create header border - thick bottom line to separate from data
workSheet["A1:L1"].Style.TopBorder.SetColor("#000000");
workSheet["A1:L1"].Style.TopBorder.Type = BorderType.Thick;
workSheet["A1:L1"].Style.BottomBorder.SetColor("#000000");
workSheet["A1:L1"].Style.BottomBorder.Type = BorderType.Thick;
// Add right border to last column
workSheet["L2:L11"].Style.RightBorder.SetColor("#000000");
workSheet["L2:L11"].Style.RightBorder.Type = BorderType.Medium;
// Create bottom border for data area
workSheet["A11:L11"].Style.BottomBorder.SetColor("#000000");
workSheet["A11:L11"].Style.BottomBorder.Type = BorderType.Medium;
// Apply complete border around summary section
var summaryRange = workSheet["A12:L12"];
summaryRange.Style.TopBorder.Type = BorderType.Double;
summaryRange.Style.BottomBorder.Type = BorderType.Double;
summaryRange.Style.LeftBorder.Type = BorderType.Thin;
summaryRange.Style.RightBorder.Type = BorderType.Thin;
summaryRange.Style.SetBorderColor("#0070C0"); // Blue borders
using IronXL;
using IronXl.Styles;
// Create header border - thick bottom line to separate from data
workSheet["A1:L1"].Style.TopBorder.SetColor("#000000");
workSheet["A1:L1"].Style.TopBorder.Type = BorderType.Thick;
workSheet["A1:L1"].Style.BottomBorder.SetColor("#000000");
workSheet["A1:L1"].Style.BottomBorder.Type = BorderType.Thick;
// Add right border to last column
workSheet["L2:L11"].Style.RightBorder.SetColor("#000000");
workSheet["L2:L11"].Style.RightBorder.Type = BorderType.Medium;
// Create bottom border for data area
workSheet["A11:L11"].Style.BottomBorder.SetColor("#000000");
workSheet["A11:L11"].Style.BottomBorder.Type = BorderType.Medium;
// Apply complete border around summary section
var summaryRange = workSheet["A12:L12"];
summaryRange.Style.TopBorder.Type = BorderType.Double;
summaryRange.Style.BottomBorder.Type = BorderType.Double;
summaryRange.Style.LeftBorder.Type = BorderType.Thin;
summaryRange.Style.RightBorder.Type = BorderType.Thin;
summaryRange.Style.SetBorderColor("#0070C0"); // Blue borders
Imports IronXL
Imports IronXl.Styles
' Create header border - thick bottom line to separate from data
workSheet("A1:L1").Style.TopBorder.SetColor("#000000")
workSheet("A1:L1").Style.TopBorder.Type = BorderType.Thick
workSheet("A1:L1").Style.BottomBorder.SetColor("#000000")
workSheet("A1:L1").Style.BottomBorder.Type = BorderType.Thick
' Add right border to last column
workSheet("L2:L11").Style.RightBorder.SetColor("#000000")
workSheet("L2:L11").Style.RightBorder.Type = BorderType.Medium
' Create bottom border for data area
workSheet("A11:L11").Style.BottomBorder.SetColor("#000000")
workSheet("A11:L11").Style.BottomBorder.Type = BorderType.Medium
' Apply complete border around summary section
Dim summaryRange = workSheet("A12:L12")
summaryRange.Style.TopBorder.Type = BorderType.Double
summaryRange.Style.BottomBorder.Type = BorderType.Double
summaryRange.Style.LeftBorder.Type = BorderType.Thin
summaryRange.Style.RightBorder.Type = BorderType.Thin
summaryRange.Style.SetBorderColor("#0070C0") ' Blue borders
IronXL, İnce, Orta, Kalın, Çift, Noktalı, ve Kesik çizgiler dahil olmak üzere çeşitli çerçeve türlerini destekler. Her çerçeve kenarı bağımsız olarak stillendirilir.
How Do I Use Excel Formulas in C#?
IronXL, otomatik hesaplamayla güçlü formül desteği sunar:
// Use built-in aggregation functions for ranges
decimal sum = workSheet["A2:A11"].Sum();
decimal avg = workSheet["B2:B11"].Avg();
decimal max = workSheet["C2:C11"].Max();
decimal min = workSheet["D2:D11"].Min();
// Assign calculated values to cells
workSheet["A12"].Value = sum;
workSheet["B12"].Value = avg;
workSheet["C12"].Value = max;
workSheet["D12"].Value = min;
// Or use Excel formulas directly
workSheet["A12"].Formula = "=SUM(A2:A11)";
workSheet["B12"].Formula = "=AVERAGE(B2:B11)";
workSheet["C12"].Formula = "=MAX(C2:C11)";
workSheet["D12"].Formula = "=MIN(D2:D11)";
// Complex formulas with multiple functions
workSheet["E12"].Formula = "=IF(SUM(E2:E11)>50000,\"Over Budget\",\"On Track\")";
workSheet["F12"].Formula = "=SUMIF(F2:F11,\">5000\")";
// Percentage calculations
workSheet["G12"].Formula = "=G11/SUM(G2:G11)*100";
workSheet["G12"].FormatString = "0.00%";
// Ensure all formulas calculate
workSheet.EvaluateAll();
// Use built-in aggregation functions for ranges
decimal sum = workSheet["A2:A11"].Sum();
decimal avg = workSheet["B2:B11"].Avg();
decimal max = workSheet["C2:C11"].Max();
decimal min = workSheet["D2:D11"].Min();
// Assign calculated values to cells
workSheet["A12"].Value = sum;
workSheet["B12"].Value = avg;
workSheet["C12"].Value = max;
workSheet["D12"].Value = min;
// Or use Excel formulas directly
workSheet["A12"].Formula = "=SUM(A2:A11)";
workSheet["B12"].Formula = "=AVERAGE(B2:B11)";
workSheet["C12"].Formula = "=MAX(C2:C11)";
workSheet["D12"].Formula = "=MIN(D2:D11)";
// Complex formulas with multiple functions
workSheet["E12"].Formula = "=IF(SUM(E2:E11)>50000,\"Over Budget\",\"On Track\")";
workSheet["F12"].Formula = "=SUMIF(F2:F11,\">5000\")";
// Percentage calculations
workSheet["G12"].Formula = "=G11/SUM(G2:G11)*100";
workSheet["G12"].FormatString = "0.00%";
// Ensure all formulas calculate
workSheet.EvaluateAll();
' Use built-in aggregation functions for ranges
Dim sum As Decimal = workSheet("A2:A11").Sum()
Dim avg As Decimal = workSheet("B2:B11").Avg()
Dim max As Decimal = workSheet("C2:C11").Max()
Dim min As Decimal = workSheet("D2:D11").Min()
' Assign calculated values to cells
workSheet("A12").Value = sum
workSheet("B12").Value = avg
workSheet("C12").Value = max
workSheet("D12").Value = min
' Or use Excel formulas directly
workSheet("A12").Formula = "=SUM(A2:A11)"
workSheet("B12").Formula = "=AVERAGE(B2:B11)"
workSheet("C12").Formula = "=MAX(C2:C11)"
workSheet("D12").Formula = "=MIN(D2:D11)"
' Complex formulas with multiple functions
workSheet("E12").Formula = "=IF(SUM(E2:E11)>50000,""Over Budget"",""On Track"")"
workSheet("F12").Formula = "=SUMIF(F2:F11,"">5000"")"
' Percentage calculations
workSheet("G12").Formula = "=G11/SUM(G2:G11)*100"
workSheet("G12").FormatString = "0.00%"
' Ensure all formulas calculate
workSheet.EvaluateAll()
Range sınıfı, hızlı hesaplamalar için Sum, Average, Max ve Min gibi yöntemler sağlar. Daha karmaşık senaryolar için, Formula özelliğini kullanarak Excel formüllerini doğrudan ayarlayın.
{t:(IronXL'nin yerleşik .Sum(), .Avg(), .Max() ve .Min() yöntemlerini tercih edin — bunlar tür güvenli olup formül sözdizimi hatalarını önler.)}
Çalışma Sayfası ve Yazdırma Özelliklerini Nasıl Ayarlarım?
IronXL'yi kullanarak, tek tek çalışma sayfalarını koruyun, satır ve sütunları dondurun ve yazdırma formatı seçeneklerini ayarlayın.
Çalışma Sayfası Özelliklerini Nasıl Yapılandırabilirim?
Çalışma sayfalarını koruyun ve görüntüleme seçeneklerini kontrol edin:
// Protect worksheet with password to prevent unauthorized changes
workSheet.ProtectSheet("SecurePassword123");
// Freeze panes to keep headers visible while scrolling
workSheet.CreateFreezePane(0, 1); // Freeze first row
// workSheet.CreateFreezePane(1, 1); // Freeze first row and column
// Set worksheet visibility options
workSheet.ViewState = WorkSheetViewState.Visible; // or Hidden, VeryHidden
// Configure gridlines and headers
workSheet.ShowGridLines = true;
workSheet.ShowRowColHeaders = true;
// Set zoom level for better viewing
workSheet.Zoom = 85; // 85% zoom
// Protect worksheet with password to prevent unauthorized changes
workSheet.ProtectSheet("SecurePassword123");
// Freeze panes to keep headers visible while scrolling
workSheet.CreateFreezePane(0, 1); // Freeze first row
// workSheet.CreateFreezePane(1, 1); // Freeze first row and column
// Set worksheet visibility options
workSheet.ViewState = WorkSheetViewState.Visible; // or Hidden, VeryHidden
// Configure gridlines and headers
workSheet.ShowGridLines = true;
workSheet.ShowRowColHeaders = true;
// Set zoom level for better viewing
workSheet.Zoom = 85; // 85% zoom
' Protect worksheet with password to prevent unauthorized changes
workSheet.ProtectSheet("SecurePassword123")
' Freeze panes to keep headers visible while scrolling
workSheet.CreateFreezePane(0, 1) ' Freeze first row
' workSheet.CreateFreezePane(1, 1); // Freeze first row and column
' Set worksheet visibility options
workSheet.ViewState = WorkSheetViewState.Visible ' or Hidden, VeryHidden
' Configure gridlines and headers
workSheet.ShowGridLines = True
workSheet.ShowRowColHeaders = True
' Set zoom level for better viewing
workSheet.Zoom = 85 ' 85% zoom
Çalışma sayfası koruması, yanlışlıkla yapılan değişiklikleri önlerken, buzlu pano, önemli satır veya sütunları kaydırma sırasında görünür tutar.

Şekil 7 - Kaydırma sırasında donmuş başlık satırı görünür kalır

Şekil 8 - Parola koruması yetkisiz düzenlemeleri engeller
Sayfa ve Yazdırma Ayarlarını Nasıl Yapılandırabilirim?
IronXL ile profesyonel yazdırma seçeneklerini ayarlayın:
using IronXl.Printing;
// Define print area to exclude empty cells
workSheet.SetPrintArea("A1:L12");
// Configure page orientation for wide data
workSheet.PrintSetup.PrintOrientation = PrintOrientation.Landscape;
// Set paper size for standard printing
workSheet.PrintSetup.PaperSize = PaperSize.A4;
// Adjust margins for better layout (in inches)
workSheet.PrintSetup.LeftMargin = 0.5;
workSheet.PrintSetup.RightMargin = 0.5;
workSheet.PrintSetup.TopMargin = 0.75;
workSheet.PrintSetup.BottomMargin = 0.75;
// Configure header and footer
workSheet.PrintSetup.HeaderMargin = 0.3;
workSheet.PrintSetup.FooterMargin = 0.3;
// Scale to fit on one page
workSheet.PrintSetup.FitToPage = true;
workSheet.PrintSetup.FitToHeight = 1;
workSheet.PrintSetup.FitToWidth = 1;
// Add print headers/footers
workSheet.Header.Center = "Monthly Budget Report";
workSheet.Footer.Left = DateTime.Now.ToShortDateString();
workSheet.Footer.Right = "Page &P of &N"; // Page numbering
using IronXl.Printing;
// Define print area to exclude empty cells
workSheet.SetPrintArea("A1:L12");
// Configure page orientation for wide data
workSheet.PrintSetup.PrintOrientation = PrintOrientation.Landscape;
// Set paper size for standard printing
workSheet.PrintSetup.PaperSize = PaperSize.A4;
// Adjust margins for better layout (in inches)
workSheet.PrintSetup.LeftMargin = 0.5;
workSheet.PrintSetup.RightMargin = 0.5;
workSheet.PrintSetup.TopMargin = 0.75;
workSheet.PrintSetup.BottomMargin = 0.75;
// Configure header and footer
workSheet.PrintSetup.HeaderMargin = 0.3;
workSheet.PrintSetup.FooterMargin = 0.3;
// Scale to fit on one page
workSheet.PrintSetup.FitToPage = true;
workSheet.PrintSetup.FitToHeight = 1;
workSheet.PrintSetup.FitToWidth = 1;
// Add print headers/footers
workSheet.Header.Center = "Monthly Budget Report";
workSheet.Footer.Left = DateTime.Now.ToShortDateString();
workSheet.Footer.Right = "Page &P of &N"; // Page numbering
Imports IronXl.Printing
' Define print area to exclude empty cells
workSheet.SetPrintArea("A1:L12")
' Configure page orientation for wide data
workSheet.PrintSetup.PrintOrientation = PrintOrientation.Landscape
' Set paper size for standard printing
workSheet.PrintSetup.PaperSize = PaperSize.A4
' Adjust margins for better layout (in inches)
workSheet.PrintSetup.LeftMargin = 0.5
workSheet.PrintSetup.RightMargin = 0.5
workSheet.PrintSetup.TopMargin = 0.75
workSheet.PrintSetup.BottomMargin = 0.75
' Configure header and footer
workSheet.PrintSetup.HeaderMargin = 0.3
workSheet.PrintSetup.FooterMargin = 0.3
' Scale to fit on one page
workSheet.PrintSetup.FitToPage = True
workSheet.PrintSetup.FitToHeight = 1
workSheet.PrintSetup.FitToWidth = 1
' Add print headers/footers
workSheet.Header.Center = "Monthly Budget Report"
workSheet.Footer.Left = DateTime.Now.ToShortDateString()
workSheet.Footer.Right = "Page &P of &N" ' Page numbering
IPrintSetup sınıfı, Excel'in PRINT ayarlarıyla eşleşen kapsamlı PRINT yapılandırma seçenekleri sunar.

Şekil 9 - Manzara yönlendirmesi ve özel kenar boşlukları ile yazdırma önizlemesi
Excel Çalışma Kitabımı Nasıl Kaydederim?
Çalışma kitabınızı çeşitli formatlarda kaydedin:
// Save as XLSX (recommended for modern Excel)
workBook.SaveAs("Budget.xlsx");
// Save as XLS for legacy compatibility
workBook.SaveAs("Budget.xls");
// Save as CSV for data exchange
workBook.SaveAsCsv("Budget.csv");
// Save as JSON for web applications
workBook.SaveAsJson("Budget.json");
// Save to stream for web downloads or cloud storage
using (var stream = new MemoryStream())
{
workBook.SaveAs(stream);
byte[] excelData = stream.ToArray();
// Send to client or save to cloud
}
// Save with specific encoding for international characters
workBook.SaveAsCsv("Budget_UTF8.csv", System.Text.Encoding.UTF8);
// Save as XLSX (recommended for modern Excel)
workBook.SaveAs("Budget.xlsx");
// Save as XLS for legacy compatibility
workBook.SaveAs("Budget.xls");
// Save as CSV for data exchange
workBook.SaveAsCsv("Budget.csv");
// Save as JSON for web applications
workBook.SaveAsJson("Budget.json");
// Save to stream for web downloads or cloud storage
using (var stream = new MemoryStream())
{
workBook.SaveAs(stream);
byte[] excelData = stream.ToArray();
// Send to client or save to cloud
}
// Save with specific encoding for international characters
workBook.SaveAsCsv("Budget_UTF8.csv", System.Text.Encoding.UTF8);
' Save as XLSX (recommended for modern Excel)
workBook.SaveAs("Budget.xlsx")
' Save as XLS for legacy compatibility
workBook.SaveAs("Budget.xls")
' Save as CSV for data exchange
workBook.SaveAsCsv("Budget.csv")
' Save as JSON for web applications
workBook.SaveAsJson("Budget.json")
' Save to stream for web downloads or cloud storage
Using stream = New MemoryStream()
workBook.SaveAs(stream)
Dim excelData() As Byte = stream.ToArray()
' Send to client or save to cloud
End Using
' Save with specific encoding for international characters
workBook.SaveAsCsv("Budget_UTF8.csv", System.Text.Encoding.UTF8)
IronXL, XLSX, XLS, CSV, TSV ve JSON dahil olmak üzere birden fazla dışa aktarma formatını destekler. Save yöntemi, dosya uzantısından formatı otomatik olarak belirler.
- XLSX / XLS: Biçimlendirme, formüller ve birden fazla sayfa ile tam Excel formatı
- CSV: Veri değişimi için sade metin — dosya başına bir sayfayı dışa aktarır
- JSON: Web API'leri ve veri hatları için yapılandırılmış çıktı
- Stream: Bellek içi çıktı için — web indirmeleri veya bulut depolama için kullanışlı
Özet
Bu eğitim, Microsoft Office bağımlılıkları olmadan C#'da Excel dosyalarının nasıl oluşturulacağını gösterdi. Çalışma kitabı oluşturma, hücre manipülasyonu, biçimlendirme, formül kullanımı ve çeşitli kaydetme seçenekleri dahil temel Excel işlemlerini öğrendiniz. IronXL'nun sezgisel API'si, .NET geliştiricileri için Excel otomasyonunu basit hale getirir.
Daha gelişmiş özellikler için hücreleri birleştirmeyi ve grafikler oluşturmayı keşfedin. IronXL'yi üretimde kullanmaya hazır mısınız? Ücretsiz denemenizi başlatın veya lisanslama seçeneklerini görüntüleyin.
Sonraki Adım Nedir?
Artık C#'da Excel dosyaları oluşturabildiğinize göre, bu ilgili IronXL özelliklerini keşfedin:
- Mevcut Excel Dosyalarını Okuma ve Düzenleme
- Excel'de Hücreleri Birleştirme
- C#'da Excel Grafiklerini Oluşturma
- Elektronik Tablo Formatları Arasında Dönüştürme
- IronXL API Referansı
WorkBook``WorkSheet``WorkBook.Create``CreateWorkSheet``CreateWorkSheet("name")``GetWorkSheet("name")``Cell.Value``$"A{i}"``Range``FormatString``Style.SetBackgroundColor``Range``Sum()``Avg()``Max()``Min()``Formula``PrintSetup``SaveAs
Sıkça Sorulan Sorular
Interop kullanmadan C#'ta Excel dosyaları nasıl oluşturabilirim?
IronXL, WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLSX) basit bir API sağlıyor ve bu yöntem, Microsoft Office kurulumu gerektirmeden herhangi bir .NET platformunda çalışıyor.
Excel dosya oluşturma C# ile hangi platformları destekler?
IronXL, Windows, macOS, Linux, Docker, Azure ve AWS ortamlarında çalışan .NET 10, .NET 9, .NET 8, .NET Core, .NET Framework 4.6.2+ üzerine Excel dosya oluşturmayı destekler.
Excel oluşturma için bir C# kütüphanesi nasıl yüklenir?
Visual Studio'da NuGet Paket Yöneticisi aracılığıyla IronXL'yi kurun, PM> Install-Package IronXL.Excel komutunu kullanın ya da doğrudan nuget.org'dan indirin.
Program aracılığıyla yeni bir Excel çalışma kitabı nasıl oluşturulur?
IronXL kullanarak bir çalışma kitabı oluşturmak için WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX) kullanın, ardından workbook.CreateWorkSheet("SheetName") ile çalışma sayfaları ekleyin.
C# kullanarak bir Excel çalışma sayfasında hücre değerlerini nasıl ayarlarım?
IronXL'de hücre değerlerini sezgisel bir sözdizimi kullanarak ayarlayın: worksheet["A1"].Value = "Hello World" veya aralıklar ayarlayın: worksheet["A1:A10"].Value = 100.
Excel hücrelerine biçimlendirme uygulamak mümkün mü?
Evet, IronXL zengin bir biçimlendirme desteği sunar, arka plan renkleri (cell.Style.SetBackgroundColor("#FF0000")), sınırlar, yazı tipleri ve sayı formatları dahil.
C#'ta Excel formülleri nasıl kullanılır?
IronXL'un Formula özelliği ile formüller uygulayın: worksheet["A1"].Formula = "=SUM(B1:B10)", veya range.Sum(), range.Avg() gibi yerleşik yöntemleri kullanın.
Bir Excel çalışma sayfasını parola ile nasıl korurum?
IronXL kullanarak çalışma sayfalarını worksheet.ProtectSheet("YourPassword") ile yetkisiz değişiklikleri önlemek için koruyun.
Excel dosyaları için yazıcı ayarlarını nasıl yapılandırırım?
IronXL'ün PrintSetup'ını kullanarak yazıcı özelliklerini ayarlayın: worksheet.PrintSetup.PrintOrientation = PrintOrientation.Landscape ve worksheet.SetPrintArea("A1:Z100") kullanın.
Excel çalışma kitabını farklı formatlarda nasıl kaydederim?
IronXL'ün SaveAs metodunu kullanarak çalışma kitaplarını şu şekilde kaydedin: workbook.SaveAs("file.xlsx") ve diğer formatlar için SaveAsCsv(), SaveAsJson() kullanın.
Veritabanından veri alarak Excel sayfasını nasıl doldurabilirim?
IronXL kullanarak veritabanından veri çekip yöntemler yardımıyla hücrelere ayarlayarak çalışma sayfalarını doldurun: worksheet["A1"].Value = dataFromDatabase gibi.
C# kullanarak Excel sayfasına dondurulmuş paneller nasıl uygularım?
IronXL ile çalışma sayfalarında worksheet.FreezePanes(1, 1) kullanarak kolay gezinti için üst satır ve en sol sütunu kilitleyin.

