# Einführung in IronXL for Python
IronXL for Python ist eine leistungsstarke Bibliothek, die von Iron Software entwickelt wurde und Softwareentwicklern die Möglichkeit bietet, Excel-Dateien (XLS, XLSX und CSV) in Python 3-Projekten zu erstellen, zu lesen und zu bearbeiten.
IronXL for Python erfordert nicht, dass Excel auf Ihrem Server oder Interop installiert ist. IronXL for Python bietet eine schnellere und intuitivere API als `Microsoft.Office.Interop.Excel`.
IronXL for Python baut auf dem Erfolg und der Popularität von IronXL for .NET auf.
## Installieren Sie IronXL for Python
### Voraussetzungen
Um IronXL for Python verwenden zu können, stellen Sie bitte sicher, dass auf Ihrem Computer die folgende Softwarevoraussetzung erfüllt ist:
1. **.NET 6.0 SDK** : IronXL for Python basiert auf der IronXL .NET-Bibliothek, insbesondere auf .NET 6.0. Daher ist es notwendig, das [.NET 6.0 SDK](https://dotnet.microsoft.com/en-us/download/dotnet/6.0) auf Ihrem Rechner installiert zu haben, um IronXL for Python verwenden zu können.
2. **Python**: Laden Sie die neueste Version von Python 3.x von der offiziellen Python-Website herunter: [https://www.python.org/downloads/](https://www.python.org/downloads/). Wählen Sie während des Installationsvorgangs die Option aus, Python zum System-PATH hinzuzufügen, damit es über die Befehlszeile zugänglich ist.
3. **Pip** : Pip wird üblicherweise ab Python 3.4 mit der Python-Installation mitgeliefert. Je nach Ihrer Python-Installation müssen Sie jedoch möglicherweise prüfen, ob pip bereits installiert ist oder es separat installieren.
4. **IronXL-Bibliothek:** Die IronXL-Bibliothek kann über pip hinzugefügt werden. Verwenden Sie den folgenden Befehl, um IronXL mit pip zu installieren:
```shell
:ProductInstall
```
[[t:(Um eine bestimmte Version von IronXL zu installieren, verwenden Sie bitte die folgende Syntax: `==2023.x.x`. Zum Beispiel können Sie den Befehl `pip install ironxl==2023.x.x` ausführen.)]]
[[i:(Auf einigen Systemen könnte Python 2.x noch die Standardversion sein. In solchen Fällen müssen Sie möglicherweise explizit den Befehl `pip3` anstelle von `pip` verwenden, um sicherzustellen, dass Sie Pip for Python 3 verwenden.)]]
## Ein Excel-Dokument lesen
Das Einlesen von Daten aus einer Excel-Datei mit IronXL for Python erfordert nur wenige Codezeilen.
```python
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-1.py
```
## Neue Excel-Dokumente erstellen
Um Excel-Dokumente in Python zu erstellen, bietet IronXL for Python eine einfache und schnelle Schnittstelle.
```python
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-2.py
```
## Exportieren als CSV, XLS, XLSX, JSON oder XML
Wir können außerdem viele gängige strukturierte Tabellenkalkulationsdateiformate speichern oder exportieren.
```python
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-3.py
```
## Zellen und Bereiche formatieren
Excel-Zellen und -Bereiche können mithilfe des Style-Objekts formatiert werden.
```python
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-4.py
```
## Bereiche sortieren
Mit IronXL for Python können wir einen Bereich von Excel-Zellen mithilfe von Range sortieren.
```python
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-5.py
```
## Formeln bearbeiten
Das Bearbeiten einer Excel-Formel ist so einfach wie das Zuweisen eines Wertes mit einem `=`-Gleichheitszeichen am Anfang. Die Formel wird live berechnet.
```python
:path=/static-assets/excel-python/content-code-examples/get-started/get-started-6.py
```
## Warum IronXL for Python wählen?
IronXL for Python bietet eine benutzerfreundliche API für Entwickler zum Lesen und Schreiben von Excel-Dokumenten.
IronXL for Python benötigt weder die Installation von Microsoft Excel auf Ihrem Server noch Excel Interop, um auf Excel-Dokumente zuzugreifen. Dadurch wird die Arbeit mit Excel-Dateien in Python zu einer sehr schnellen und einfachen Aufgabe.
## Lizenzierung & Support verfügbar
**IronXL for Python** kann kostenlos in Entwicklungsumgebungen verwendet und getestet werden.
Für die Nutzung in Live-Projekten [ist der Erwerb einer Lizenz erforderlich](/python/excel/licensing/) . Es sind auch [30-Tage-Testlizenzen](trial-license) erhältlich.
Unsere vollständige Liste mit Codebeispielen, Tutorials, Lizenzinformationen und Dokumentation finden Sie unter: [IronXL for Python](/python/excel/) .
Für weitere Unterstützung und Anfragen [fragen Sie unser Team](#live-chat-support).
IronXL for Python ist eine leistungsstarke Bibliothek, die von Iron Software entwickelt wurde und Softwareentwicklern die Möglichkeit bietet, Excel-Dateien (XLS, XLSX und CSV) in Python 3-Projekten zu erstellen, zu lesen und zu bearbeiten.
IronXL for Python erfordert nicht, dass Excel auf Ihrem Server oder Interop installiert ist. IronXL for Python bietet eine schnellere und intuitivere API als Microsoft.Office.Interop.Excel.
IronXL for Python baut auf dem Erfolg und der Popularität von IronXL for .NET auf.
Installieren Sie IronXL for Python
Voraussetzungen
Um IronXL for Python verwenden zu können, stellen Sie bitte sicher, dass auf Ihrem Computer die folgende Softwarevoraussetzung erfüllt ist:
.NET 6.0 SDK : IronXL for Python basiert auf der IronXL .NET-Bibliothek, insbesondere auf .NET 6.0. Daher ist es notwendig, das .NET 6.0 SDK auf Ihrem Rechner installiert zu haben, um IronXL for Python verwenden zu können.
Python: Laden Sie die neueste Version von Python 3.x von der offiziellen Python-Website herunter: https://www.python.org/downloads/. Wählen Sie während des Installationsvorgangs die Option aus, Python zum System-PATH hinzuzufügen, damit es über die Befehlszeile zugänglich ist.
Pip : Pip wird üblicherweise ab Python 3.4 mit der Python-Installation mitgeliefert. Je nach Ihrer Python-Installation müssen Sie jedoch möglicherweise prüfen, ob pip bereits installiert ist oder es separat installieren.
IronXL-Bibliothek: Die IronXL-Bibliothek kann über pip hinzugefügt werden. Verwenden Sie den folgenden Befehl, um IronXL mit pip zu installieren:
> pip install ironxl
pip install ironxl
Tipps: Um eine bestimmte Version von IronXL zu installieren, verwenden Sie bitte die folgende Syntax: ==2023.x.x. Zum Beispiel können Sie den Befehl pip install ironxl==2023.x.x ausführen.
Hinweis:: Auf einigen Systemen könnte Python 2.x noch die Standardversion sein. In solchen Fällen müssen Sie möglicherweise explizit den Befehl pip3 anstelle von pip verwenden, um sicherzustellen, dass Sie Pip for Python 3 verwenden.
Ein Excel-Dokument lesen
Das Einlesen von Daten aus einer Excel-Datei mit IronXL for Python erfordert nur wenige Codezeilen.
# Load the necessary module from IronXLfrom ironxl importWorkBook# 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 workbookworksheet = 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 outputprint(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}'")
# 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}'")
Python
Neue Excel-Dokumente erstellen
Um Excel-Dokumente in Python zu erstellen, bietet IronXL for Python eine einfache und schnelle Schnittstelle.
from ironxl importWorkBook, ExcelFileFormat, BorderType# Import necessary classes from ironxl# Create a new Excel WorkBook document in XLSX formatworkbook = WorkBook.create(ExcelFileFormat.XLSX)# Set metadata for the workbookworkbook.metadata.author = "IronXL"# Add a new blank worksheet named "main_sheet" to the workbookworksheet = 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 colorworksheet["A2"].style.bottom_border.set_color("#ff6600")worksheet["A2"].style.bottom_border.type = BorderType.double# Save the Excel file with the specified filenameworkbook.save_as("NewExcelFile.xlsx")
from 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")
Python
Exportieren als CSV, XLS, XLSX, JSON oder XML
Wir können außerdem viele gängige strukturierte Tabellenkalkulationsdateiformate speichern oder exportieren.
# Assuming workSheet is an existing instance of WorkSheetworkSheet.SaveAs("NewExcelFile.xls")workSheet.SaveAs("NewExcelFile.xlsx")workSheet.SaveAsCsv("NewExcelFile.csv")workSheet.SaveAsJson("NewExcelFile.json")workSheet.SaveAsXml("NewExcelFile.xml")
# 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")
Python
Zellen und Bereiche formatieren
Excel-Zellen und -Bereiche können mithilfe des Style-Objekts formatiert werden.
# Set cell's value and stylesworkSheet["A1"].Value = "Hello World"workSheet["A2"].Style.BottomBorder.SetColor("#ff6600")workSheet["A2"].Style.BottomBorder.Type = BorderType.Double
# Set cell's value and styles
workSheet["A1"].Value = "Hello World"
workSheet["A2"].Style.BottomBorder.SetColor("#ff6600")
workSheet["A2"].Style.BottomBorder.Type = BorderType.Double
Python
Bereiche sortieren
Mit IronXL for Python können wir einen Bereich von Excel-Zellen mithilfe von Range sortieren.
# Import IronXL library for handling Excel filesfrom ironxl importWorkBook# Load an existing Excel workbook# 'sample.xls' is the file name of the Excel workbook to be loadedworkbook = 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 0worksheet = 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 A8selected_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 largestselected_range.SortAscending()# Save the changes made to the workbook, including the sorted range# The workbook's state is updated with the changes after executionworkbook.Save()
# 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()
Python
Formeln bearbeiten
Das Bearbeiten einer Excel-Formel ist so einfach wie das Zuweisen eines Wertes mit einem =-Gleichheitszeichen am Anfang. Die Formel wird live berechnet.
# Set a formulaworkSheet["A1"].Formula = "=SUM(A2:A10)"# Get the calculated valuesum_ = workSheet["A1"].DecimalValue
# Set a formula
workSheet["A1"].Formula = "=SUM(A2:A10)"
# Get the calculated value
sum_ = workSheet["A1"].DecimalValue
Python
Warum IronXL for Python wählen?
IronXL for Python bietet eine benutzerfreundliche API für Entwickler zum Lesen und Schreiben von Excel-Dokumenten.
IronXL for Python benötigt weder die Installation von Microsoft Excel auf Ihrem Server noch Excel Interop, um auf Excel-Dokumente zuzugreifen. Dadurch wird die Arbeit mit Excel-Dateien in Python zu einer sehr schnellen und einfachen Aufgabe.
Lizenzierung & Support verfügbar
IronXL for Python kann kostenlos in Entwicklungsumgebungen verwendet und getestet werden.
Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender Handbücher.