Python용 IronXL 소개

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronXL for Python은 Iron Software 에서 개발한 강력한 라이브러리로, 소프트웨어 엔지니어가 Python 3 프로젝트에서 Excel(XLS, XLSX 및 CSV) 파일을 생성, 읽기 및 편집할 수 있도록 지원합니다.

IronXL for Python은 서버에 Excel을 설치하거나 Interop을 설정할 필요가 없습니다. IronXL for Python은 Microsoft.Office.Interop.Excel보다 빠르고 직관적인 API를 제공합니다.

Python용 IronXL .NET 용 IronXL 의 성공과 인기를 기반으로 구축되었습니다.

Python용 IronXL 설치하세요.

필수 조건

Python용 IronXL 사용하려면 컴퓨터에 다음 필수 소프트웨어가 설치되어 있는지 확인하십시오.

  1. .NET 6.0 SDK : Python용 IronXL 기본 기술로 IronXL .NET 라이브러리, 특히 .NET 6.0을 사용합니다. 따라서 IronXL for Python을 사용하려면 컴퓨터에 .NET 6.0 SDK가 설치되어 있어야 합니다.
  2. Python : Python 공식 웹사이트에서 Python 3.x 최신 버전을 다운로드하여 설치하세요.https://www.python.org/downloads/ . 설치 과정에서 Python을 시스템 PATH에 추가하는 옵션을 선택해야 합니다. 이렇게 하면 명령줄에서 Python에 접근할 수 있습니다.
  3. Pip : Pip은 일반적으로 Python 3.4 이상 버전부터 Python 설치에 포함되어 있습니다. 하지만 Python 설치 환경에 따라 pip가 이미 설치되어 있는지 확인하거나 별도로 설치해야 할 수도 있습니다.
  4. IronXL 라이브러리: IronXL 라이브러리는 pip를 통해 추가할 수 있습니다. 아래 명령어를 사용하여 pip로 IronXL 설치하세요.
pip install IronXL

특정 버전의 IronXL을 설치하려면 다음 구문을 사용하세요: ==2023.x.x. 예를 들어, 명령어 pip install ironxl==2023.x.x을 실행할 수 있습니다.

참고해 주세요일부 시스템에서는 Python 2.x가 여전히 기본 버전일 수 있습니다. 이러한 경우 pip 대신에 pip3 명령어를 명시적으로 사용하여 Python 3용 Pip을 사용하고 있는지 확인해야 할 수 있습니다.

엑셀 문서 읽기

Python용 IronXL 사용하여 Excel 파일에서 데이터를 읽는 데는 몇 줄의 코드만 필요합니다.

: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}'")
PYTHON

새 엑셀 문서 만들기

Python으로 엑셀 문서를 생성하려면 IronXL for Python이 간단하고 빠른 인터페이스를 제공합니다.

:path=/static-assets/excel-python/content-code-examples/get-started/get-started-2.py
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

CSV, XLS, XLSX, JSON 또는 XML 형식으로 내보내기

또한 다양한 일반적인 스프레드시트 파일 형식으로 저장하거나 내보낼 수 있습니다.

: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")
PYTHON

셀 및 범위 스타일링

Excel 셀과 범위는 Style 객체를 사용하여 스타일을 지정할 수 있습니다.

: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.Double
PYTHON

정렬 범위

Python용 IronXL 사용하면 Range 함수를 이용하여 Excel 셀 범위를 정렬할 수 있습니다.

: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()
PYTHON

수식 편집

Excel 수식을 편집하는 것은 시작 부분에 = 등호 기호와 함께 값을 할당하는 것만큼 쉽습니다. 해당 공식은 실시간으로 계산됩니다.

: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
PYTHON

Python 개발에 IronXL 선택해야 하는 이유는 무엇일까요?

IronXL for Python은 개발자가 Excel 문서를 읽고 쓸 수 있는 간편한 API를 제공합니다.

Python용 IronXL 서버에 Microsoft Excel을 설치하거나 Excel 문서에 액세스하기 위해 Excel Interop을 설치할 필요가 없습니다. 이 덕분에 Python에서 엑셀 파일을 다루는 작업이 매우 빠르고 간단해집니다.

라이선스 및 지원 가능

IronXL for Python은 개발 환경에서 무료로 사용하고 테스트할 수 있습니다.

실제 프로젝트에서 사용하려면 라이선스를 구매하세요 . 30일 평가판 라이선스 도 이용 가능합니다.

전체 코드 예제, 튜토리얼, 라이선스 정보 및 문서 목록을 보려면 IronXL for Python 페이지를 방문하세요.

더 자세한 지원이나 문의 사항이 있으시면 저희 팀에 문의해 주세요.

커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.

시작할 준비 되셨나요?
버전: 2026.3 방금 출시되었습니다
Still Scrolling Icon

아직도 스크롤하고 계신가요?

빠른 증거를 원하시나요?
샘플을 실행하세요 데이터가 스프레드시트로 변환되는 것을 지켜보세요.