博客
关于我
python 实现自动化办公 excel文件的打开与内容写入 提取数据
阅读量:76 次
发布时间:2019-02-26

本文共 1218 字,大约阅读时间需要 4 分钟。

Python??Excel????????????????????

?????Python??Excel??????????????????????????????openpyxl??????????Excel???????????????????????????????

from openpyxl import load_workbook, Workbookimport os# ??Excel??source_file = '10??????.xlsx'wb = load_workbook(source_file)ws = wb.active# ?????????max_row = 10  # ????????# ????rows = []for row in ws.iter_rows(max_row=max_row, values_only=True):    rows.append(row)# ?????new_file = '?????.xlsx'new_wb = Workbook()new_ws = new_wb.active# ?????????for row in rows:    new_ws.append(row)# ????new_wb.save(new_file)

### ?????

1. **?????**???`openpyxl`????Excel???`os`????????????????????2. **?????**?`load_workbook`?????????Excel???`wb`????????`ws`?????????3. **??????**?`max_row`?????10????????????10????4. **????**???`ws.iter_rows`???????`values_only=True`???????????????5. **?????**?`new_wb`?????????`new_ws`???????6. **????**???????????????????7. **????**???`new_wb.save`??????????`new_file`?

?????

  • ???????source_file?new_file?????????????????????????
  • ?????????????max_row?????10???????????10????
  • ??????????.xlsx??????????.xls????????????????

?????

  • ??????????????????max_row??
  • ???????????????ws?wb??????
  • ??????????????os.path????????????????

????????????Excel???????????????????

转载地址:http://hmfz.baihongyu.com/

你可能感兴趣的文章
Orcale表被锁
查看>>
svn访问报错500
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>
org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
查看>>
org.tinygroup.serviceprocessor-服务处理器
查看>>
org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
查看>>
org/hibernate/validator/internal/engine
查看>>
SQL-36 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表。
查看>>
ORM sqlachemy学习
查看>>
Ormlite数据库
查看>>
orm总结
查看>>
os.path.join、dirname、splitext、split、makedirs、getcwd、listdir、sep等的用法
查看>>