怎么用通过cgi执行python脚本(excel转换为html的脚本)
#!/usr/bin/python3#-*-coding:UTF-8-*-importcgiimportcodecsimportpandasaspdimportreimp...
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import cgi
import codecs
import pandas as pd
import re
import time
import shutil
import os
print ("Content-type:text/html")
print ()
Today = (time.strftime("%Y%m%d", time.localtime()))
#excel 所在路径
Tyqs_excel_path = "sss_"+Today+".xls"
#html存放路径
Tyqs_html_path = "sss"+Today+".html"
#EXCEL转换为 html
def Excel_Html(Excelfile_path,Htmlfile_path):
excelFile = r''+Excelfile_path
df = pd.DataFrame(pd.read_excel(excelFile))
df = df.replace('\n','', regex=True) #去除行尾的换行符
df.dropna(axis=0, how='any', inplace=True) #删除含有空值的行(axis:0-行操作(默认),1-列操作; how:any-只要有空值就删除(默认),all-全部为空值才删除; inplace:False-返回新的数据>集(默认),True-在愿数据集上操作)
df.style.set_properties(**{'text-align': 'right'})
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
pd.set_option('display.max_colwidth',1500)#设置列的宽度,以防止出现省略号
with codecs.open(Htmlfile_path,'w') as html_file:
print ("22222222")
html_file.write(df.to_html(header = True,index = False,float_format=lambda x: format(x,',.0f')))
print ("============1111111")
return
Excel_Html(Tyqs_excel_path,Tyqs_html_path)
请问上面的代码要怎么样才可以通过cgi(浏览器访问)的方式执行,print ("22222222")这一步都正常,就 html_file.write(df.to_html(header = True,index = False,float_format=lambda x: format(x,',.0f'))) 出问题了,请问我需要怎么样改才可以? 展开
# -*- coding: UTF-8 -*-
import cgi
import codecs
import pandas as pd
import re
import time
import shutil
import os
print ("Content-type:text/html")
print ()
Today = (time.strftime("%Y%m%d", time.localtime()))
#excel 所在路径
Tyqs_excel_path = "sss_"+Today+".xls"
#html存放路径
Tyqs_html_path = "sss"+Today+".html"
#EXCEL转换为 html
def Excel_Html(Excelfile_path,Htmlfile_path):
excelFile = r''+Excelfile_path
df = pd.DataFrame(pd.read_excel(excelFile))
df = df.replace('\n','', regex=True) #去除行尾的换行符
df.dropna(axis=0, how='any', inplace=True) #删除含有空值的行(axis:0-行操作(默认),1-列操作; how:any-只要有空值就删除(默认),all-全部为空值才删除; inplace:False-返回新的数据>集(默认),True-在愿数据集上操作)
df.style.set_properties(**{'text-align': 'right'})
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
pd.set_option('display.max_colwidth',1500)#设置列的宽度,以防止出现省略号
with codecs.open(Htmlfile_path,'w') as html_file:
print ("22222222")
html_file.write(df.to_html(header = True,index = False,float_format=lambda x: format(x,',.0f')))
print ("============1111111")
return
Excel_Html(Tyqs_excel_path,Tyqs_html_path)
请问上面的代码要怎么样才可以通过cgi(浏览器访问)的方式执行,print ("22222222")这一步都正常,就 html_file.write(df.to_html(header = True,index = False,float_format=lambda x: format(x,',.0f'))) 出问题了,请问我需要怎么样改才可以? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询