1. python 怎么生出成一个表格,并发送邮件
>>>fromdjango.core.mailimportsend_mail>>>subject='thisisatestmail'>>>message='<table><tr><td>123</td><td>456</td></tr></table>'>>>send_mail(subject,message,sender_mail,[user.mail],fail_silently=False)2. 如何用python创建excel表格
可以安装xlsxwriter库
看简例:
importxlsxwriter
#创建新表格
workbook=xlsxwriter.Workbook('test.xlsx')
worksheet=workbook.add_worksheet()
#表格的内容
expenses=(
['Rent',1000],
['Gas',100],
['Food',300],
['Gym',50],
)
#想象表格的布局,坐标0,0对应A,1
row=0
col=0
#填充每个单元格
foritem,costin(expenses):
worksheet.write(row,col,item)
worksheet.write(row,col+1,cost)
row+=1
workbook.close()
3. 用python怎么print出一张完整的表格内容
显示一张完整的表格(即包含表格线、表头以及表体内容),有多种方法,根据显示的应用场合不同,采取的方法也不同,以下试举例供参考:
1、调用表格类软件显示。如,可以直接调用 excel 软件,来打开/生成表格并显示。
2、调用 word 类字处理软件。
3、使用 html 之类的代码生成超文本格式表格,用浏览器软件显示。
4、直接用字符表格的形式显示出来。如,可以使用制表符制作并显示一个字符式的表格:
4. python的easygui怎么制作一个表格
你好,下面是一个简单表格的例子
import easygui as g
m1 = g.multenterbox(msg='[*真实姓名]为必填项\n[*手机号码]为必填项\n[*E-mail]为必填项\n',\
fields=('*用户名','*真实姓名','固定电话','*手机号码','*QQ','E-mail'))
print(m1)
5. 请问python如何使用tk绘制图片这种表格,并且可以在空白处添加数据后保存文件
这明显不是 tk 干的活啊。 这应该是一张web 表格,或者 WORD 模板 才合适。
6. 如何用python操作excel
指定选取三列然后挑选出同时满足>=1或者同时<=-1的 将其所有数据存入新的csv表格中
程序如下:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2014-04-10 21:47:56
# @Function: 指定选取三列然后挑选出同时满足>=1或者同时<=-1的 将其所有数据存入新的csv表格中
# @Author : BeginMan
import os
import string
import xlrd
import xlwt
def get_data():
"""获取excel数据源"""
file = r'C:\Users\Administrator\Desktop\pytool\xlrd\initial_log_data.xls' # 改成自己的路径
filepath = raw_input(u'请将xls文件路径粘贴进去,如果程序里已经指定了文件则按Enter键继续:')
is_valid = False # 验证文件
try:
filepath = [file, filepath][filepath != '']
print filepath
# 判断给出的路径是不是xls格式
if os.path.isfile(filepath):
filename = os.path.basename(filepath)
if filename.split('.')[1] == 'xls':
is_valid = True
data = None
if is_valid:
data = xlrd.open_workbook(filepath)
except Exception, e:
print u'你操作错误:%s' %e
return None
return data
def handle_data():
"""处理数据"""
data = get_data()
if data:
col_format = ['B', 'C', 'D'] # 指定的列
inp = raw_input(u'请选择指定的三列,用逗号分隔,默认的是B,C,D(英文逗号,不区分大小写),如果选择默认则按Enter键继续:\n')
try:
inp = inp.split(',')
col_format = [col_format,inp][len([i for i in inp if i in string.letters]) == 3]
col_format = [i.upper() for i in col_format] # 转换成大写
table = data.sheet_by_index(0) # 选取第一个工作区
nrows = table.nrows # 行数
ncols = table.ncols # 列数
str_upcase = [i for i in string.uppercase] # 所有大写字母
i_upcase = range(len(str_upcase)) # 对应的数字
ncols_dir = dict(zip(str_upcase,i_upcase)) # 格式成字典
col_index = [ncols_dir.get(i) for i in col_format] # 获取指定列所对应的索引
# 选取的三列是否同时满足 >=1或者同时<=-1
print u'正在检索中……'
count = 0
result = []
for i in xrange(nrows):
cell_0 = table.cell(i,col_index[0]).value
cell_1 = table.cell(i,col_index[1]).value
cell_2 = table.cell(i,col_index[2]).value
if (cell_0>=1 and cell_1>=1 and cell_2>=1) or (cell_0<=-1 and cell_1<=-1 and cell_2<=-1):
result.append(table.row_values(i)) # 将符合要求的一行添加进去
count += 1
print u'该文件中共%s行,%s列,其中满足条件的共有%s条数据' %(nrows, ncols, count)
print u'正在写入数据……'
col_name = col_format[0]+col_format[1]+col_format[2]
if write_data(result, col_name):
print u'写入成功!'
except Exception, e:
print u'你操作错误:%s' %e
return None
else:
print u'操作失败'
return None
def write_data(data, name):
"""写入数据,data为符合条件的数据列表,name表示指定的哪三个列,以此命名"""
file = xlwt.Workbook()
table = file.add_sheet(name,cell_overwrite_ok=True)
l = 0 # 表示行
for line in data:
c = 0 # 表示一行下的列数
for col in line:
table.write(l,c,line[c])
c += 1
l += 1
defatul_f = r'C:\Users\Administrator\Desktop\pytool\xlrd' # 默认路径
f = raw_input(u'请选择保存文件的路径:按回车跳过:')
f_name = r'\%s.xls' % name
filepath = [defatul_f+f_name, f+f_name][f != '']
file.save(filepath)
return True
def main():
handle_data()
if __name__ == '__main__':
main()
7. python能用来制作表格吗
可以的,python有很多扩展模块
比如xlwt、xlrd等等,可以用作xls表格文件的读写处理
完全可以实现表格制作功能
8. 关于如何用python 编辑 excel表格
#不理解你的意思,如果要是读出来每行都是你给的格式,输出格式是你写的话,很好弄。
line=file.readlines()
f=open('result.txt','w')
foriinrange(len(line)):
eachline=line[i].split(' ')
arry1=[]
iflen(eachline)==2:
print>>f,eachline[0],'',eachline[1],arry1.append(line[i+1:i+4]),
'<',line[i+4],',',line[i+5],',',line[i+6],'>'
f.close()