Python için IronXL Kullanıma Giriş
IronXL for Python, Iron Software tarafından geliştirilen güçlü bir kütüphanedir, yazılım mühendislerine Python 3 projelerinde Excel (XLS, XLSX ve CSV) dosyalarını oluşturma, okuma ve düzenleme yeteneği sunar.
IronXL for Python, sunucunuzda Excel veya Interop'un kurulu olmasını gerektirmez. IronXL for Python, Microsoft.Office.Interop.Excel'dan daha hızlı ve daha sezgisel bir API sunar.
IronXL for Python, IronXL for .NET'in başarısı ve popülaritesi üzerine inşa edilmiştir.
Python için IronXL'i Yükleyin
Ön Koşullar
Python için IronXL'i kullanmak için, bilgisayarınızda aşağıdaki ön gereklilik yazılımlarının yüklü olduğundan emin olun:
- .NET 6.0 SDK: IronXL for Python, IronXL .NET kütüphanesine, özellikle .NET 6.0'a, altyapı teknolojisi olarak dayanır. Bu nedenle, Python için IronXL kullanabilmek için makinenize .NET 6.0 SDK'nın kurulmuş olması gereklidir.
- Python: En son sürüm Python 3.x'i resmi Python web sitesinden indirin ve kurun: https://www.python.org/downloads/. Kurulum sürecinde, Python'u komut satırından erişilebilir hale getirecek sistem PATH'ine ekleme seçeneğini seçtiğinizden emin olun.
- Pip: Pip, genellikle Python 3.4 ve sonrası yayınlarda Python kurulumu ile birlikte gelir. Ancak, Python kurulumunuza bağlı olarak, pip'in zaten kurulu olup olmadığını kontrol etmeniz veya ayrı olarak yüklemeniz gerekebilir.
- IronXL Kütüphanesi: IronXL kütüphanesi pip aracılığıyla eklenebilir. IronXL'i pip kullanarak yüklemek için aşağıdaki komutu kullanın:
pip install IronXL
==2023.x.x. Örneğin, pip install ironxl==2023.x.x.pip yerine pip3 komutunu açıkça kullanmanız gerekebilir.Bir Excel Belgesi Okuma
IronXL for Python ile bir Excel dosyasından veri okuma, birkaç satır kod gerektirir.
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-1.py# Load the necessary module from IronXL
from ironxl import WorkBook
# Load an existing Excel spreadsheet
# Replace 'sample.xlsx' with the path to your Excel file as needed.
workbook = WorkBook.load("sample.xlsx")
# Select the first worksheet from the workbook
worksheet = workbook.worksheets[0]
# Access cell A2 and get its integer value
# Ensure the correct method or property is used to fetch the integer value.
# Use 'value' to directly access the cell content.
cell_value = worksheet["A2"].value
# Print out the value of the cell A2
# Utilizing formatted strings for clear output
print(f"Cell A2 has value '{cell_value}'")
# Iterate over a range of cells and print their address and text content
# The range is defined from A2 to B10, which captures all rows in this interval.
for cell in worksheet.range("A2:B10"):
# Access each cell in the specified range
# AddressString is used to get the cell's location as a string, and Text to get its content.
print(f"Cell {cell.address} has value '{cell.text}'")Yeni Excel Belgeleri Oluşturma
Python'da Excel belgeleri oluşturmak için, IronXL for Python basit, hızlı bir arayüz sağlıyor.
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-2.pyfrom ironxl import WorkBook, ExcelFileFormat, BorderType # Import necessary classes from ironxl
# Create a new Excel WorkBook document in XLSX format
workbook = WorkBook.create(ExcelFileFormat.XLSX)
# Set metadata for the workbook
workbook.metadata.author = "IronXL"
# Add a new blank worksheet named "main_sheet" to the workbook
worksheet = workbook.create_worksheet("main_sheet")
# Add data to cell "A1"
worksheet["A1"].value = "Hello World"
# Set the style for cell "A2" with a double bottom border and a specific color
worksheet["A2"].style.bottom_border.set_color("#ff6600")
worksheet["A2"].style.bottom_border.type = BorderType.double
# Save the Excel file with the specified filename
workbook.save_as("NewExcelFile.xlsx")CSV, XLS, XLSX, JSON veya XML olarak Dışa Aktarma
Ayrıca birçok yaygın yapılandırılmış elektronik tablo dosya formatı olarak kaydedebilir veya ihraç edebiliriz.
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-3.py# Assuming workSheet is an existing instance of WorkSheet
workSheet.SaveAs("NewExcelFile.xls")
workSheet.SaveAs("NewExcelFile.xlsx")
workSheet.SaveAsCsv("NewExcelFile.csv")
workSheet.SaveAsJson("NewExcelFile.json")
workSheet.SaveAsXml("NewExcelFile.xml")Hücreleri ve Aralıkları Stilleme
Excel hücreleri ve aralıklar Styling nesnesi kullanılarak biçimlendirilebilir.
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-4.py# Set cell's value and styles
workSheet["A1"].Value = "Hello World"
workSheet["A2"].Style.BottomBorder.SetColor("#ff6600")
workSheet["A2"].Style.BottomBorder.Type = BorderType.DoubleAralıkları Sıralama
Python için IronXL kullanarak, bir dizi Excel Hücresini, Aralık kullanarak sıralayabiliriz.
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-5.py# Import IronXL library for handling Excel files
from ironxl import WorkBook
# Load an existing Excel workbook
# 'sample.xls' is the file name of the Excel workbook to be loaded
workbook = WorkBook.Load("sample.xls")
# Access the first worksheet in the workbook
# WorkSheets is the collection of all sheets in the workbook,
# and we select the first one using index 0
worksheet = workbook.WorkSheets[0]
# Select a range of cells from A2 to A8 in the worksheet
# This specifies a contiguous range of cells starting from A2 and ending at A8
selected_range = worksheet["A2:A8"]
# Sort the selected range of cells in ascending order
# This operation reorders the values in the specified range from smallest to largest
selected_range.SortAscending()
# Save the changes made to the workbook, including the sorted range
# The workbook's state is updated with the changes after execution
workbook.Save()
Formülleri Düzenleme
Bir Excel formülünü düzenlemek, başına = eşittir işareti koyarak bir değer atamak kadar kolaydır. Formül, canlı olarak hesaplanacaktır.
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-6.py# Set a formula
workSheet["A1"].Formula = "=SUM(A2:A10)"
# Get the calculated value
sum_ = workSheet["A1"].DecimalValue
Neden IronXL for Python Seçmelisiniz?
IronXL for Python, geliştiriciler için Excel belgelerini okuyup yazmak için kolay bir API sunar.
IronXL for Python, sunucunuzda Microsoft Excel'in kurulumunu veya Excel belgelerine erişmek için Excel Interop'u gerektirmez. Bu, Python'da Excel dosyalarıyla çalışmayı çok hızlı ve basit bir görev haline getirir.
Lisanslama ve Destek Mevcuttur
IronXL Python için, geliştirme ortamlarında kullanım ve test için ücretsizdir.
Canlı projelerde kullanmak için bir lisans satın alın. 30 günlük Deneme lisansları da mevcuttur.
Kod örnekleri, öğreticiler, lisans bilgileri ve dokümantasyon dahil tam listemiz için ziyaret edin: IronXL Python için.
Daha fazla destek ve soru için lütfen ekibimize sorun.







