Development
파이썬 엑셀 모듈 (xlsxwriter)
chbae
2023. 4. 19. 03:18
반응형
파이썬에서 작업한 결과를 엑셀 포맷으로 저장을 하려고 찾아보니 xlsxwriter이라는 모듈이 나왔다. 사용해보니 어렵지 않았다. 필자의 환경은 Ubuntu 12.04 64bit 이다.
xlsxwriter 파이썬 모듈 설치
$ sudo pip install xlsxwriter
Example
import xlsxwriter
workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()
worksheet.write('A1', 'Hello world')
workbook.close()
Advanced Example
##############################################################################
#
# A simple example of some of the features of the XlsxWriter Python module.
#
# Copyright 2013-2015, John McNamara, jmcnamara@cpan.org
#
import xlsxwriter
# Create an new Excel file and add a worksheet.
workbook = xlsxwriter.Workbook('demo.xlsx')
worksheet = workbook.add_worksheet()
# Widen the first column to make the text clearer.
worksheet.set_column('A:A', 20)
# Add a bold format to use to highlight cells.
bold = workbook.add_format({'bold': True})
# Write some simple text.
worksheet.write('A1', 'Hello')
# Text with formatting.
worksheet.write('A2', 'World', bold)
# Write some numbers, with row/column notation.
worksheet.write(2, 0, 123)
worksheet.write(3, 0, 123.456)
# Insert an image.
worksheet.insert_image('B5', 'logo.png')
workbook.close()
Reference
- http://xlsxwriter.readthedocs.org/en/latest/getting_started.html
- http://xlsxwriter.readthedocs.org/en/latest/examples.html
- http://egloos.zum.com/mcchae/v/11120944
728x90
반응형