openpyxl读写 Excel 文件的 Python 库
openpyxl是一个Python库,用于读取/写入Excel 2010 xlsx / xlsm / xltx / xltm文件。
它的诞生是因为缺少可从Python本地读取/写入Office Open XML格式的库。
示例代码如下:
from openpyxl import Workbook wb = Workbook() # grab the active worksheet ws = wb.active # Data can be assigned directly to cells ws['A1'] = 42 # Rows can also be appended ws.append([1, 2, 3]) # Python types will automatically be converted import datetime ws['A2'] = datetime.datetime.now() # Save the file wb.save("sample.xlsx")
评论