当前位置: 首页 > news >正文

python生成表格文件_【记录】Python中生成(写入数据到)Excel文件中

想要试试,在Python中,如何将数据,导出为Excel,即把数据写入到新生成的excel文件。

1.网上看到:

其中包括,Python中,如何读取excel文件,如何写入数据到excel文件等等相关的库。

看起来应该是这方面的资料中,总结的最好的了.

2.此处暂时只需要写入数据到Excel,所以就去参考:

去看看示例代码:

貌似用起来还算简单。

然后去主页:

下载xlwt-0.7.4.tar.gz后,解压。

然后参考:

去用setup.py install去安装:D:\tmp\dev_tools\python\excel\xlwt-0.7.4.tar\xlwt-0.7.4\xlwt-0.7.4>setup.py install

running install

running build

running build_py

creating build

creating build\lib

creating build\lib\xlwt

copying xlwt\antlr.py -> build\lib\xlwt

copying xlwt\BIFFRecords.py -> build\lib\xlwt

copying xlwt\Bitmap.py -> build\lib\xlwt

copying xlwt\Cell.py -> build\lib\xlwt

copying xlwt\Column.py -> build\lib\xlwt

copying xlwt\CompoundDoc.py -> build\lib\xlwt

copying xlwt\ExcelFormula.py -> build\lib\xlwt

copying xlwt\ExcelFormulaLexer.py -> build\lib\xlwt

copying xlwt\ExcelFormulaParser.py -> build\lib\xlwt

copying xlwt\ExcelMagic.py -> build\lib\xlwt

copying xlwt\Formatting.py -> build\lib\xlwt

copying xlwt\Row.py -> build\lib\xlwt

copying xlwt\Style.py -> build\lib\xlwt

copying xlwt\UnicodeUtils.py -> build\lib\xlwt

copying xlwt\Utils.py -> build\lib\xlwt

copying xlwt\Workbook.py -> build\lib\xlwt

copying xlwt\Worksheet.py -> build\lib\xlwt

copying xlwt\__init__.py -> build\lib\xlwt

creating build\lib\xlwt\doc

copying xlwt\doc\xlwt.html -> build\lib\xlwt\doc

creating build\lib\xlwt\examples

copying xlwt\examples\big-16Mb.py -> build\lib\xlwt\examples

copying xlwt\examples\big-35Mb.py -> build\lib\xlwt\examples

copying xlwt\examples\blanks.py -> build\lib\xlwt\examples

copying xlwt\examples\col_width.py -> build\lib\xlwt\examples

copying xlwt\examples\country.py -> build\lib\xlwt\examples

copying xlwt\examples\dates.py -> build\lib\xlwt\examples

copying xlwt\examples\format.py -> build\lib\xlwt\examples

copying xlwt\examples\formulas.py -> build\lib\xlwt\examples

copying xlwt\examples\formula_names.py -> build\lib\xlwt\examples

copying xlwt\examples\hyperlinks.py -> build\lib\xlwt\examples

copying xlwt\examples\image.py -> build\lib\xlwt\examples

copying xlwt\examples\merged.py -> build\lib\xlwt\examples

copying xlwt\examples\merged0.py -> build\lib\xlwt\examples

copying xlwt\examples\merged1.py -> build\lib\xlwt\examples

copying xlwt\examples\mini.py -> build\lib\xlwt\examples

copying xlwt\examples\num_formats.py -> build\lib\xlwt\examples

copying xlwt\examples\outline.py -> build\lib\xlwt\examples

copying xlwt\examples\panes.py -> build\lib\xlwt\examples

copying xlwt\examples\parse-fmla.py -> build\lib\xlwt\examples

copying xlwt\examples\protection.py -> build\lib\xlwt\examples

copying xlwt\examples\python.bmp -> build\lib\xlwt\examples

copying xlwt\examples\row_styles.py -> build\lib\xlwt\examples

copying xlwt\examples\row_styles_empty.py -> build\lib\xlwt\examples

copying xlwt\examples\simple.py -> build\lib\xlwt\examples

copying xlwt\examples\sst.py -> build\lib\xlwt\examples

copying xlwt\examples\unicode0.py -> build\lib\xlwt\examples

copying xlwt\examples\unicode1.py -> build\lib\xlwt\examples

copying xlwt\examples\unicode2.py -> build\lib\xlwt\examples

copying xlwt\examples\wsprops.py -> build\lib\xlwt\examples

copying xlwt\examples\xlwt_easyxf_simple_demo.py -> build\lib\xlwt\examples

running install_lib

creating D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\antlr.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\BIFFRecords.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\Bitmap.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\Cell.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\Column.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\CompoundDoc.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

creating D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\doc

copying build\lib\xlwt\doc\xlwt.html -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\doc

creating D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\big-16Mb.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\big-35Mb.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\blanks.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\col_width.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\country.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\dates.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\format.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\formulas.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\formula_names.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\hyperlinks.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\image.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\merged.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\merged0.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\merged1.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\mini.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\num_formats.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\outline.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\panes.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\parse-fmla.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\protection.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\python.bmp -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\row_styles.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\row_styles_empty.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\simple.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\sst.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\unicode0.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\unicode1.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\unicode2.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\wsprops.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\examples\xlwt_easyxf_simple_demo.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples

copying build\lib\xlwt\ExcelFormula.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\ExcelFormulaLexer.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\ExcelFormulaParser.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\ExcelMagic.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\Formatting.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\Row.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\Style.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\UnicodeUtils.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\Utils.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\Workbook.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\Worksheet.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

copying build\lib\xlwt\__init__.py -> D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\antlr.py to antlr.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\BIFFRecords.py to BIFFRecords.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\Bitmap.py to Bitmap.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\Cell.py to Cell.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\Column.py to Column.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\CompoundDoc.py to CompoundDoc.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\big-16Mb.py to big-16Mb.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\big-35Mb.py to big-35Mb.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\blanks.py to blanks.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\col_width.py to col_width.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\country.py to country.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\dates.py to dates.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\format.py to format.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\formulas.py to formulas.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\formula_names.py to formula_names.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\hyperlinks.py to hyperlinks.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\image.py to image.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\merged.py to merged.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\merged0.py to merged0.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\merged1.py to merged1.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\mini.py to mini.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\num_formats.py to num_formats.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\outline.py to outline.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\panes.py to panes.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\parse-fmla.py to parse-fmla.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\protection.py to protection.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\row_styles.py to row_styles.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\row_styles_empty.py to row_styles_empty.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\simple.py to simple.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\sst.py to sst.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\unicode0.py to unicode0.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\unicode1.py to unicode1.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\unicode2.py to unicode2.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\wsprops.py to wsprops.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\examples\xlwt_easyxf_simple_demo.py to xlwt_easyxf_simple_demo.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\ExcelFormula.py to ExcelFormula.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\ExcelFormulaLexer.py to ExcelFormulaLexer.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\ExcelFormulaParser.py to ExcelFormulaParser.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\ExcelMagic.py to ExcelMagic.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\Formatting.py to Formatting.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\Row.py to Row.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\Style.py to Style.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\UnicodeUtils.py to UnicodeUtils.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\Utils.py to Utils.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\Workbook.py to Workbook.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\Worksheet.py to Worksheet.pyc

byte-compiling D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt\__init__.py to __init__.pyc

running install_egg_info

Writing D:\tmp\WordPress\DevRoot\Python27\Lib\site-packages\xlwt-0.7.4-py2.7.egg-info

然后继续参考:

去试试示例代码:import xlwt;

from datetime import datetime;

style0 = xlwt.easyxf('font: name Times New Roman, color-index red, bold on',num_format_str='#,##0.00');

style1 = xlwt.easyxf(num_format_str='D-MMM-YY');

wb = xlwt.Workbook();

ws = wb.add_sheet('A Test Sheet');

ws.write(0, 0, 1234.56, style0);

ws.write(1, 0, datetime.now(), style1);

ws.write(2, 0, 1);

ws.write(2, 1, 1);

ws.write(2, 2, xlwt.Formula("A3+B3"));

wb.save('example.xls');

然后是可以正常执行,生成对应的excel文件的,效果为:

generated-excel-effect_thumb.png

接下来,就是如何利用此库的事情了。

【总结】

想要在Python中,将数据导出到Excel文件中,可以利用xlwt,很是方便。在此感谢作者们。

相关文章:

  • springboot jwt token前后端分离_4小时开发一个SpringBoot+vue前后端分离博客项目附带源码
  • idea serialversionuid怎么生成_这样设置 IDEA,让你爽到飞起!
  • 论文英文参考文献[10]的时候后面多空格_论文干货|论文新手别急,完整的论文写作没那么难...
  • python os open_[原创] python os.open()方法
  • idea构建springboot项目右边没有maven_你们要的干货来了——实战 Spring Boot
  • 使用python下载文件_使用Python下载文件(大文件,重定向文件)
  • 为什么python现在这么火_Python为什么这么火,您怎么看的?
  • python提示line3_python中使用tab键进行提示(python3有效)
  • python字典程序题_Python练习:字典
  • python转换函数使用_【已解决】Python中,将字符串转换为函数,并且实现带参数的函数调用...
  • phpthink验证旧密码_【法制警示】宁夏一手机店老板将他人旧手机回收,竟盗取其支付宝中5000余元......
  • python dll_python调用C dll api
  • pythoncsv数据类型_pandas读取CSV文件时查看修改各列的数据类型格式
  • python标准库os的方法_Python标准库os.path包、glob包使用实例
  • python数字排序_python中如何对数字排序
  • [ JavaScript ] 数据结构与算法 —— 链表
  • IE报vuex requires a Promise polyfill in this browser问题解决
  • JavaScript实现分页效果
  • java架构面试锦集:开源框架+并发+数据结构+大企必备面试题
  • node入门
  • supervisor 永不挂掉的进程 安装以及使用
  • Vim Clutch | 面向脚踏板编程……
  • Vue实战(四)登录/注册页的实现
  • 半理解系列--Promise的进化史
  • 道格拉斯-普克 抽稀算法 附javascript实现
  • 发布国内首个无服务器容器服务,运维效率从未如此高效
  • 关于Flux,Vuex,Redux的思考
  • 如何用vue打造一个移动端音乐播放器
  • 设计模式 开闭原则
  • 使用 @font-face
  • 腾讯视频格式如何转换成mp4 将下载的qlv文件转换成mp4的方法
  • 原生 js 实现移动端 Touch 滑动反弹
  • 容器镜像
  • 新年再起“裁员潮”,“钢铁侠”马斯克要一举裁掉SpaceX 600余名员工 ...
  • #我与Java虚拟机的故事#连载14:挑战高薪面试必看
  • $GOPATH/go.mod exists but should not goland
  • (iPhone/iPad开发)在UIWebView中自定义菜单栏
  • (PWM呼吸灯)合泰开发板HT66F2390-----点灯大师
  • (附源码)ssm航空客运订票系统 毕业设计 141612
  • (规划)24届春招和25届暑假实习路线准备规划
  • (亲测成功)在centos7.5上安装kvm,通过VNC远程连接并创建多台ubuntu虚拟机(ubuntu server版本)...
  • (转)linux下的时间函数使用
  • (转)用.Net的File控件上传文件的解决方案
  • ****** 二 ******、软设笔记【数据结构】-KMP算法、树、二叉树
  • .bat批处理(一):@echo off
  • .htaccess配置常用技巧
  • .net core 连接数据库,通过数据库生成Modell
  • .NET程序员迈向卓越的必由之路
  • .NET开发人员必知的八个网站
  • @Autowired多个相同类型bean装配问题
  • @hook扩展分析
  • [20171113]修改表结构删除列相关问题4.txt
  • [AIGC] Nacos:一个简单 yet powerful 的配置中心和服务注册中心
  • [BT]BUUCTF刷题第8天(3.26)
  • [BZOJ 4034][HAOI2015]T2 [树链剖分]