PyExcel的插件,提供以文本格式显示和写入数据的功能

pyexcel-text的Python项目详细描述


https://raw.githubusercontent.com/pyexcel/pyexcel.github.io/master/images/patreon.pnghttps://api.travis-ci.org/pyexcel/pyexcel-text.svg?branch=masterhttps://codecov.io/gh/pyexcel/pyexcel-text/branch/master/graph/badge.svghttps://img.shields.io/gitter/room/gitterHQ/gitter.svg

它是pyexcel的插件并扩展 它主要通过tabulate

  • “普通”
  • “简单”
  • “网格”
  • “管道”
  • “orgtbl”
  • “RST”
  • “mediawiki”
  • “乳胶漆”
  • “乳胶书架”
  • “json”
  • “HTML”

从v0.2.7开始,也支持jsonndjson输入。

用法

有什么新消息?

>>>importpyexcelaspe>>>sheet=pe.Sheet()>>>sheet.json='[[1,2],[2,3]]'>>>sheetpyexcelsheet:+---+---+|1|2|+---+---+|2|3|+---+---+>>>highspeedrail=pe.Sheet()>>>highspeedrail.json="""
... [{"year": 1903, "country": "Germany", "speed": "206.7km/h"},
... {"year": 1964, "country": "Japan", "speed": "210km/h"},
... {"year": 2008, "country": "China", "speed": "350km/h"}]
... """>>>highspeedrail.name='High Speed Train Speed Break Through (Source: Wikipedia)'>>>highspeedrailHighSpeedTrainSpeedBreakThrough(Source:Wikipedia):+---------+-----------+------+|country|speed|year|+---------+-----------+------+|Germany|206.7km/h|1903|+---------+-----------+------+|Japan|210km/h|1964|+---------+-----------+------+|China|350km/h|2008|+---------+-----------+------+>>>henley_on_thames_facts=pe.Sheet()>>>henley_on_thames_facts.json="""
... {"area": "5.58 square meters",
... "population": "11,619",
... "civial parish": "Henley-on-Thames",
... "latitude": "51.536",
... "longitude": "-0.898"
... }""">>>henley_on_thames_factspyexcelsheet:+--------------------+------------------+----------+-----------+------------+|area|civialparish|latitude|longitude|population|+--------------------+------------------+----------+-----------+------------+|5.58squaremeters|Henley-on-Thames|51.536|-0.898|11,619|+--------------------+------------------+----------+-----------+------------+>>>ccs_insight=pe.Sheet()>>>ccs_insight.name="Worldwide Mobile Phone Shipments (Billions), 2017-2021">>>ccs_insight.json="""
... {"year": ["2017", "2018", "2019", "2020", "2021"],
... "smart phones": [1.53, 1.64, 1.74, 1.82, 1.90],
... "feature phones": [0.46, 0.38, 0.30, 0.23, 0.17]}""">>>ccs_insightpyexcelsheet:+----------------+--------------+------+|featurephones|smartphones|year|+----------------+--------------+------+|0.46|1.53|2017|+----------------+--------------+------+|0.38|1.64|2018|+----------------+--------------+------+|0.3|1.74|2019|+----------------+--------------+------+|0.23|1.82|2020|+----------------+--------------+------+|0.17|1.9|2021|+----------------+--------------+------+

以下是json的变体:

>>> highspeedrail2 = pe.Sheet()
>>> highspeedrail2.ndjson = """
... {"year": 1903, "country": "Germany", "speed": "206.7km/h"}
... {"year": 1964, "country": "Japan", "speed": "210km/h"}
... {"year": 2008, "country": "China", "speed": "350km/h"}
... """.strip()
>>> highspeedrail2.name = 'High Speed Train Speed Break Through (Source: Wikipedia)'
>>> highspeedrail2
High Speed Train Speed Break Through (Source: Wikipedia):
+---------+-----------+------+
| country | speed     | year |
+---------+-----------+------+
| Germany | 206.7km/h | 1903 |
+---------+-----------+------+
| Japan   | 210km/h   | 1964 |
+---------+-----------+------+
| China   | 350km/h   | 2008 |
+---------+-----------+------+
>>> henley_on_thames_facts2 = pe.Sheet()
>>> henley_on_thames_facts2.ndjson = """
... {"area": "5.58 square meters"}
... {"population": "11,619"}
... {"civial parish": "Henley-on-Thames"}
... {"latitude": "51.536"}
... {"longitude": "-0.898"}
... """.strip()
>>> henley_on_thames_facts2
pyexcel sheet:
+---------------+--------------------+
| area          | 5.58 square meters |
+---------------+--------------------+
| population    | 11,619             |
+---------------+--------------------+
| civial parish | Henley-on-Thames   |
+---------------+--------------------+
| latitude      | 51.536             |
+---------------+--------------------+
| longitude     | -0.898             |
+---------------+--------------------+
>>> ccs_insight2 = pe.Sheet()
>>> ccs_insight2.name = "Worldwide Mobile Phone Shipments (Billions), 2017-2021"
>>> ccs_insight2.ndjson = """
... {"year": ["2017", "2018", "2019", "2020", "2021"]}
... {"smart phones": [1.53, 1.64, 1.74, 1.82, 1.90]}
... {"feature phones": [0.46, 0.38, 0.30, 0.23, 0.17]}
... """.strip()
>>> ccs_insight2
pyexcel sheet:
+----------------+------+------+------+------+------+
| year           | 2017 | 2018 | 2019 | 2020 | 2021 |
+----------------+------+------+------+------+------+
| smart phones   | 1.53 | 1.64 | 1.74 | 1.82 | 1.9  |
+----------------+------+------+------+------+------+
| feature phones | 0.46 | 0.38 | 0.3  | 0.23 | 0.17 |
+----------------+------+------+------+------+------+

简单

>>>importpyexcelaspe>>>content=[...["Column 1","Column 2","Column 3"],...[1,2,3],...[4,5,6],...[7,8,9]...]>>>sheet=pe.Sheet(content)>>>print(sheet.simple)pyexcelsheet:------------------------Column1Column2Column3123456789------------------------>>>sheet.name_columns_by_row(0)>>>print(sheet.simple)pyexcelsheet:Column1Column2Column3------------------------------123456789

网格

>>>print(sheet.grid)pyexcelsheet:+------------+------------+------------+|Column1|Column2|Column3|+============+============+============+|1|2|3|+------------+------------+------------+|4|5|6|+------------+------------+------------+|7|8|9|+------------+------------+------------+

mediawiki

>>>multiple_sheets={...'Sheet 1':...[...[1.0,2.0,3.0],...[4.0,5.0,6.0],...[7.0,8.0,9.0]...],...'Sheet 2':...[...['X','Y','Z'],...[1.0,2.0,3.0],...[4.0,5.0,6.0]...],...'Sheet 3':...[...['O','P','Q'],...[3.0,2.0,1.0],...[4.0,3.0,2.0]...]...}>>>book=pe.Book(multiple_sheets)>>>book.save_as("myfile.mediawiki")>>>myfile=open("myfile.mediawiki")>>>print(myfile.read())Sheet1:{|class="wikitable"style="text-align: left;"|+<!--caption-->|-|align="right"|1||align="right"|2||align="right"|3|-|align="right"|4||align="right"|5||align="right"|6|-|align="right"|7||align="right"|8||align="right"|9|}Sheet2:{|class="wikitable"style="text-align: left;"|+<!--caption-->|-|X||Y||Z|-|1.0||2.0||3.0|-|4.0||5.0||6.0|}Sheet3:{|class="wikitable"style="text-align: left;"|+<!--caption-->|-|O||P||Q|-|3.0||2.0||1.0|-|4.0||3.0||2.0|}>>>myfile.close()

html

>>>book.save_as("myfile.html")>>>myfile=open("myfile.html")>>>print(myfile.read())# doctest: +SKIPSheet1:<table><tr><tdstyle="text-align: right;">1</td><tdstyle="text-align: right;">2</td><tdstyle="text-align: right;">3</td></tr><tr><tdstyle="text-align: right;">4</td><tdstyle="text-align: right;">5</td><tdstyle="text-align: right;">6</td></tr><tr><tdstyle="text-align: right;">7</td><tdstyle="text-align: right;">8</td><tdstyle="text-align: right;">9</td></tr></table>Sheet2:<table><tr><td>X</td><td>Y</td><td>Z</td></tr><tr><td>1.0</td><td>2.0</td><td>3.0</td></tr><tr><td>4.0</td><td>5.0</td><td>6.0</td></tr></table>Sheet3:<table><tr><td>O</td><td>P</td><td>Q</td></tr><tr><td>3.0</td><td>2.0</td><td>1.0</td></tr><tr><td>4.0</td><td>3.0</td><td>2.0</td></tr></table>

请注意,表0.7.7在tr标签周围附加了一个tbody标签。

依赖关系

  • 制表

更改日志

0.2.7-30.07.2017

已更新:

  1. 从纯json格式读取特定的数据结构:二维 数组,列表或二维列表和记录列表的字典。
  2. 读取换行分隔的json。二维数组 或者支持二维列表和记录列表。

0.2.6-19.06.2017

已更新:

  1. 支持PyExcel v0.5.0。插件接口更新为renderer
  2. 已删除不推荐的“另存为”和“另存为”内存函数

0.2.5-28.10.2016

已更新:

  1. 支持PyExcel v0.4.0

0.2.4-28.10.2016

添加:

  1. 支持PyExcel v0.3.0

0.2.3-14.07.2016

添加:

  1. json格式:序列化日期和日期时间

已更新:

  1. 如果工作表有行名,其json输出将成为记录(字典列表) 而不是行名与其余行值的字典。

0.2.2-01.06.2016

  1. 快速修复错误,请参见issue #27

0.2.1-01.06.2016

  1. PyExcel IO 0.2.0和PyExcel 0.2.2的紧凑性

0.2.0-23.04.2016

这是对整个扩展的完全重写。

已添加

  1. HTML支持
  2. 支持PyExcel 0.2.0的生成器输出
  3. 测试目标中的pypy和pypy3
  4. 支持文件流和点符号,例如pyexcel.sheet.rst将返回它的rst文本表示。

已更新

  1. #8,将头作为选项写入(false)以禁用头写入
  2. 多页书的json输出将按其页名排序。
  3. pyexcel文本不再是pyexcel io插件,而是pyexcel.sources插件。

0.1.1-30.01.2016

已更新
  1. #2,修复setup.py中的错误

0.1.0-17.01.2016

已更新
  1. 支持PyExcel 0.2.0

0.0.3-12.06.2015

已更新
  1. #1,对齐api接口
    使用其他PyExcel插件,例如“另存为”、“另存书本为”

0.0.2-30.11.2014

已更新
  1. 支持PyExcel 0.0.9

2014年11月20日

初始版本

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java播放流媒体音乐   LWJGL中的java纹理未显示   java从父集合中删除时删除子对象   mysql希望在我的代码中添加验证,如果表不存在,它应该用java创建新表   java我可以关闭客户端的socket而不引起服务器端的EOFEException吗?   java Primefaces对话框框架咆哮和showMessageInDialog不工作   hadoop配置单元无法初始化类java。网网络接口   关键字中缺少oracle11g Java iBatis   java在RESTAPI中创建PUT和POST端点,而不创建GET端点?   java Math abs和ceil输出编译错误   java Tomcat 8.017代md5及其摘要。球棒   java SpringBean配置xml文件在IteliJ Idea中加载   java为什么在使用Powershell指定Xms和Xmx时,它们什么都不做,但通过Netbeans IDE可以正常工作?   java Drools项目构建失败,kjar打包从7.7版开始