python36--将数据保存为excel
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xlwt
import os class ExcelHelper(object):
@staticmethod
def create_excel(column_heads, row_items, file_path):
book = xlwt.Workbook(encoding='utf-8', style_compression=0)
sheet = book.add_sheet('sheet1', cell_overwrite_ok=True)
column_count = len(column_heads)
row_count = len(row_items)
# 写入列标题
for column_id in range(column_count):
sheet.write(0, column_id, column_heads[column_id])
# 遍历所有行
for row_id in range(row_count):
row_item = row_items[row_id]
# 遍历每行的所有列
for column_id in range(column_count):
# 将每一行的对应列写sheet中
sheet.write(row_id + 1, column_id, row_item[column_id])
# 保存文件
if os.path.exists(file_path):
os.remove(file_path)
book.save(file_path) def demo():
column_heads = ["姓名", "学校", "出生日期", "年龄"]
row_items = [
["张删", "北京大学", "1988-01-02", 29],
["王二小", "清华大学", "1989-01-02", 28],
]
file_path = r"d:\t1.xls"
ExcelHelper.create_excel(
column_heads=column_heads,
row_items=row_items,
file_path=file_path
)
print("file {0} was created".format(file_path)) if __name__ == '__main__':
demo()
引入xlwt需要安装openpyxl包
=========================================================================

python36--将数据保存为excel的更多相关文章
- mfc 导出数据保存成excel和txt格式
最近做了一些东西,项目到了收尾的工作.不过这次我没有参与到控件机器的功能的那一部分,都是主管自己写的.不过,所有的控件重写都是由我来做的.还有数据库这一方面是我和主管共同完成的.不过还不错,主管写一部 ...
- 将matlab数据保存为excel文件
摘录网址:https://blog.csdn.net/wangh0802/article/details/70312415 参考网址:https://jingyan.baidu.com/article ...
- Qt将表格table保存为excel(odbc方式)
首先是保存excel的方法,可参照: http://dzmlmszp.blog.163.com/blog/static/179271962014819111812531/ ok,进入正题. 现在我有一 ...
- pandans导出Excel并将数据保存到不同的Sheet表中
数据存在mongodb中,按照类别导出到Excel文件,问题是想把同一类的数据放到一个sheet表中,最后只导出到一个excel文件中# coding=utf-8import pandas as pd ...
- 【HTML5版】导出Table数据并保存为Excel
首发我的博客 http://blog.meathill.com/tech/js/export-table-data-into-a-excel-file.html 最近接到这么个需求,要把<tab ...
- 如何使用免费控件将Word表格中的数据导入到Excel中
我通常使用MS Excel来存储和处理大量数据,但有时候经常会碰到一个问题—我需要的数据存储在word表格中,而不是在Excel中,这样处理起来非常麻烦,尤其是在数据比较庞大的时候, 这时我迫切地需要 ...
- 将List下载到本地保存为Excel
直接附上代码 /// <summary> /// 将List保存为Excel /// </summary> /// <typeparam name="T&quo ...
- 效率最高的Excel数据导入---(c#调用SSIS Package将数据库数据导入到Excel文件中【附源代码下载】) 转
效率最高的Excel数据导入---(c#调用SSIS Package将数据库数据导入到Excel文件中[附源代码下载]) 本文目录: (一)背景 (二)数据库数据导入到Excel的方法比较 ...
- Visual Basic 2012 借助DataGridView控件将SQL server2012 数据导入到Excel 2010
摘 要: SQL Server 2012 数据和Excel 2010之间的连接和数据的传输,本篇文章主要针对的是SQL Server 2012 数据导入到Excel 2010文件中.Excel软件对 ...
随机推荐
- Vue组件中引入jQuery
一.安装jQuery依赖 在使用jQuery之前,我们首先要通过以下命令来安装jQuery依赖: npm install jquery --save # 如果你更换了淘宝镜像,可以使用cnpm来安装, ...
- OneZero第三周第三次站立会议(2016.4.6)
1. 时间: 13:05--13:15 共计10分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...
- windows 10 开发学习资料,Windows-universal-samples学习笔记系列一:App settings
windows 10 通用代码范例: https://github.com/Microsoft/Windows-universal-samples 相关视频:https://mix.office.co ...
- MVVM中viewmodel的理解
网上有人写了这段话,我也有同感,特别是第一种用法,很重要,后一种用法,我觉得是把第一种用法加入controller中了. 第一种 “view model” 是 “model for the view” ...
- 70.app上架被拒(info.plist定位参数配置)
问题一: Your app declares support for location in the UIBackgroundModes key in your Info.plist file but ...
- 48.UIButton上的字体居右对齐
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; button.titleLabel.textAlignment = NSTe ...
- linux vi操作
1.“i”键,进入编辑状态.可以看到命令的下方出现了“--INSERT--”字样,表示成功进入了编辑模式; 2.“Esc”键,退出编辑模式.并在此时输入“:wq”以退出并保存
- C++航空系统
/* * SHA-256 implementation, Mark 2 * * Copyright (c) 2010,2014 Ilya O. Levin, http://www.literateco ...
- jmeter读取csv文件
操作步骤: 1.读取csv文件 2.编辑httpSampler
- tp5,thinkphp5,隐藏index.php,隐藏入口文件
一.找到/public/.htaccess文件 Apache: <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews R ...