赞
踩
Py之openpyxl:openpyxl库的简介、安装、使用方法之详细攻略
目录
openpyxl是一个用于读取/编写Excel 2010 xlsx/xlsm/xltx/xltm文件的Python库。它是由于缺乏从Python中读取/编写Office Open XML格式的现有库而诞生的。所有这些都归功于PHPExcel团队,因为openpyxl最初是基于PHPExcel的。
官方文档:openpyxl - A Python library to read/write Excel 2010 xlsx/xlsm files — openpyxl 3.1.2 documentation
- pip install openpyxl
- pip install -i https://mirrors.aliyun.com/pypi/simple --upgrade openpyxl
- 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")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。