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()