Excel 워크시트 Python에서 주석 추가

MS Excel은 추가 정보를 제공하기 위해 워크시트의 셀에 주석을 추가하는 것을 지원합니다. 다양한 경우에 주석을 사용하여 공식을 설명합니다. 또한 MS Excel에서는 주석의 글꼴 크기, 높이, 너비 등을 정의할 수 있습니다. 이 기사에서는 Python을 사용하여 프로그래밍 방식으로 Excel 워크시트에 주석을 추가하는 방법을 배웁니다.

Excel에서 주석을 추가하는 Python API

Excel 워크시트의 셀에 주석을 추가하기 위해 Java를 통한 Python용 Aspose.Cells를 사용합니다. API를 사용하면 Python 애플리케이션 내에서 Excel 파일을 생성, 수정 및 변환할 수 있습니다. API를 다운로드하거나 다음 pip 명령을 사용하여 설치할 수 있습니다.

pip install aspose-cells

Python에서 Excel 워크시트에 주석 추가

다음은 Python을 사용하여 Excel 워크시트의 셀에 주석을 추가하는 단계입니다.

다음 코드 샘플은 Python을 사용하여 Excel 워크시트에 주석을 추가하는 방법을 보여줍니다.

# Instantiating a Workbook object
workbook = Workbook("workbook.xlsx")

# Obtaining the reference of the first worksheet by passing its sheet index
worksheet = workbook.getWorksheets().get(0)

# Adding a comment to "F5" cell
commentIndex = worksheet.getComments().add("F5")

# Accessing the newly added comment
comment = worksheet.getComments().get(commentIndex)

# Setting the comment note
comment.setNote("Hello Aspose!")

# Saving the Excel file
workbook.save("output.xlsx")

Excel에서 주석에 서식 적용

다음은 Python을 사용하여 Excel의 주석에 서식을 적용하는 단계입니다.

다음 코드 샘플은 Excel에서 주석 서식을 설정하는 방법을 보여줍니다.

# Instantiating a Workbook object
workbook = Workbook("workbook.xlsx")

# Obtaining the reference of the first worksheet by passing its sheet index
worksheet = workbook.getWorksheets().get(0)

# Adding a comment to "F5" cell
commentIndex = worksheet.getComments().add("F5")

# Accessing the newly added comment
comment = worksheet.getComments().get(commentIndex)

# Setting the comment note
comment.setNote("Hello Aspose!")

# Setting the font size of a comment to 14
comment.getFont().setSize(14)

# Setting the font of a comment to bold
comment.getFont().setBold(True)

# Setting the height of the font to 10
comment.setHeightCM(10)

# Setting the width of the font to 2
comment.setWidthCM(2)

# Saving the Excel file
workbook.save("output.xlsx")  

무료 라이선스 받기

임시 라이선스를 사용하여 평가 제한 없이 Java를 통해 Python용 Aspose.Cell을 사용할 수 있습니다.

결론

이 기사에서는 Python을 사용하여 Excel 워크시트의 셀에 주석을 추가하는 방법을 배웠습니다. 또한 프로그래밍 방식으로 주석에 서식을 적용하는 방법을 살펴보았습니다. 문서를 사용하여 API의 다른 기능을 탐색할 수 있습니다. 질문이 있는 경우 포럼에 자유롭게 게시하십시오.

또한보십시오