展开全部

|

pyexcel-xls is a tiny wrapper library to read, manipulate and write data in xls format and it can read xlsx and xlsm fromat. You are likely to use it with pyexcel.

Known constraints

Fonts, colors and charts are not supported.

Installation

You can install it via pip:

$ pip install pyexcel-xls

or clone it and install it:

$ git clone hexcel-xls.git$ cd pyexcel-xls$ python setup.py install

Usage

As a standalone library

Write to an xls file

Here’s the sample code to write a dictionary to an xls file:

>>> from pyexcel_xls import save_data>>> data = OrderedDict() # from collections import OrderedDict>>> data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})>>> data.update({"Sheet 2": [["row 1", "row 2", "row 3"]]})>>> save_data("your_file.xls", data)

Read from an xls file

Here’s the sample code:

>>> from pyexcel_xls import get_data>>> data = get_data("your_file.xls")>>> import json>>> print(json.dumps(data)){"Sheet 1": [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], "Sheet 2": [["row 1", "row 2", "row 3"]]}

Write an xls to memory

Here’s the sample code to write a dictionary to an xls file:

>>> from pyexcel_xls import save_data>>> data = OrderedDict()>>> data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})>>> data.update({"Sheet 2": [[7, 8, 9], [10, 11, 12]]})>>> io = StringIO()>>> save_data(io, data)>>> # do something with the io>>> # In reality, you might give it to your http response>>> # object for downloading

Read from an xls from memory

Continue from previous example:

>>> # This is just an illustration>>> # In reality, you might deal with xls file upload>>> # where you will read from requests.FILES['YOUR_XL_FILE']>>> data = get_data(io)>>> print(json.dumps(data)){"Sheet 1": [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]], "Sheet 2": [[7.0, 8.0, 9.0], [10.0, 11.0, 12.0]]}

As a pyexcel plugin

Import it in your file to enable this plugin:

from pyexcel.ext import xls

Please note only pyexcel version 0.0.4+ support this.

Reading from an xls file

Here is the sample code:

>>> import pyexcel as pe>>> from pyexcel.ext import xls>>> sheet = pe.get_book(file_name="your_file.xls")>>> sheetSheet Name: Sheet 1+---+---+---+|62616964757a686964616fe78988e69d8331333365633837 1 | 2 | 3 |+---+---+---+| 4 | 5 | 6 |+---+---+---+Sheet Name: Sheet 2+-------+-------+-------+| row 1 | row 2 | row 3 |+-------+-------+-------+

Writing to an xls file

Here is the sample code:

>>> sheet.save_as("another_file.xls")

Reading from a IO instance

You got to wrap the binary content with stream to get xls working:

>>> # This is just an illustration>>> # In reality, you might deal with xls file upload>>> # where you will read from requests.FILES['YOUR_XLS_FILE']>>> xlsfile = "another_file.xls">>> with open(xlsfile, "rb") as f:...     content = f.read()...     r = pe.get_book(file_type="xls", file_content=content)...     print(r)...Sheet Name: Sheet 1+---+---+---+| 1 | 2 | 3 |+---+---+---+| 4 | 5 | 6 |+---+---+---+Sheet Name: Sheet 2+-------+-------+-------+| row 1 | row 2 | row 3 |+-------+-------+-------+

Writing to a StringIO instance

You need to pass a StringIO instance to Writer:

>>> data = [...     [1, 2, 3],...     [4, 5, 6]... ]>>> io = StringIO()>>> sheet = pe.Sheet(data)>>> sheet.save_to_memory("xls", io)>>> # then do something with io>>> # In reality, you might give it to your http response>>> # object for downloading

License

New BSD License

Known IssuesIf a zero was typed in a DATE formatted field in xls, you will get “01/01/1900”.

If a zero was typed in a TIME formatted field in xls, you will get “00:00:00”.

Dependencies

xlrd

xlwt-future

pyexcel-io >= 0.0.4

python做值班表_如何用Python 实现自动排班相关推荐

  1. python打开excel表_如何用python打开excel

    最近看到好几次群里有人问xlwt.wlrd的问题,怎么说呢,如果是office2007刚出来,大家用xlsx文件用不习惯,还可以理解,这都10年过去了喂,就算没有进化到office2016,还在用of ...

  2. 用python做一张图片_如何用python下载一张图片

    如何用python下载一张图片 这里要用到的主要工具是requests这个工具,需要先安装这个库才能使用,该库衍生自urllib这个库,但是要比它更好用.多数人在做爬虫的时候选择它,是个不错的选择. ...

  3. python做人工智能对话_如何用Python制作聊天机器人?

    ,现在几乎30%的任务都是通过聊天机器人完成的.公司使用聊天机器人来提供诸如客户支持.生成信息等服务.以Siri.Alexa等为例,聊天机器人如何在我们的日常生活中发挥作用就变得 ,现在几乎30%的任 ...

  4. 如何用python做计算软件_如何用Python写一个计算器软件 附带效果图

    1 import tkinter #导入tkinter模块 2 3 root =tkinter.Tk()4 root.minsize(280,500)5 root.title('李蛟龙的计算器')6 ...

  5. python的out模式_如何用python中的DataFrame列的模式替换NA值?

    我对Python(和本网站)完全陌生,目前正试图用它们的模式替换特定数据帧列中的NA值.我试过了各种不起作用的方法.请帮我看看我做错了什么:如何用python中的DataFrame列的模式替换NA值? ...

  6. python交互界面数据分析_如何用 Python 和 Streamlit 做交互式数据分析产品?

    「本文参与少数派 2019 年度征文 + 效率有心得」 不用学前端编程,你就能用 Python 简单高效写出漂亮的交互式 Web 应用,将你的数据分析成果立即展示给团队和客户. 痛点 从我开始折腾数据 ...

  7. 用python输出一张九九乘法表_如何用python输出九九乘法表?有哪些方法?

    大家学了学习python这么久,大概都可以将python融汇贯通使用了吧,今天小编就教大家一个案例,融汇python主要的方法内容,一起来看下吧~ 概述 今天主要介绍如何用Python实现九九乘法表( ...

  8. 如何用python输出九九乘法表_如何用python输出九九乘法表?有哪些方法?

    大家学了学习python这么久,大概都可以将python融汇贯通使用了吧,今天小编就教大家一个案例,融汇python主要的方法内容,一起来看下吧~ 概述 今天主要介绍如何用Python实现九九乘法表( ...

  9. python做值班表预测_Django model一张表中两个字段设置外键参考另一张表两个字段...

    class products(models.Model): MODE_CHOICES=(('week','周'),('day','日')) productname=models.CharField(m ...

最新文章

  1. MySQL基本了解与使用
  2. 记录PCLVisualizer问题
  3. 下拉框联动_058-ajax之三级联动案例分析
  4. 【git学习】统计git项目某user的代码量
  5. 苹果笔记本能不能用python_“苹”除了苹果还能组哪些词?苹组词,释义及造句汇总!...
  6. Android studio http 代理设置
  7. 域控制器服务器的管理维护,域控制器管理 向备份要安全(图)
  8. 在Python中什么是slicing?
  9. c语言处理机调度实验报告,操作系统实验处理机调度C语言实现.docx
  10. php代码连接mysql数据库,php连接mysql数据库代码
  11. python基础——经营第一个项目,如何将python学得更6 ?
  12. 小程序 图片加载慢卡
  13. 【PR】PR剪辑视频编辑软件视频去字幕
  14. 坐标转换工具类:84坐标系,火星坐标系,与百度坐标系之间的互相转换
  15. ubuntu下安装FoxitReader pdf阅读器
  16. 135编辑器怎么复制html,135编辑器复制粘贴文字的方法
  17. 知识图到文本的生成(十一)
  18. 线段树--暴力修改专题浅谈
  19. 解决xcel数据导入MySQL数据库【日期数据格式混乱】的问题
  20. nodejs获取当前连接的网络ip

热门文章

  1. java如何循环输出一个表格,Java编程for循环输出俄文字母表
  2. 【AD小知识】PCB之自动布线及快速布局技巧
  3. 小程序短视频项目———视频展示页面开发
  4. VM安装CentOS虚拟机详细教程
  5. go 进阶 多路复用支持: 一. netpoller 初始化
  6. 学Python太枯燥?不多BB这几个有趣的python 库让你爱上python
  7. Synchronized锁的使用
  8. 实用算法的分析与程序设计——递推法(倒推法)
  9. Flutter 无埋点SDK实现
  10. ubuntu无法上网