Python实现将excel文件转化为html文件


需要转化的excel文件(nsrxx.xlsx):

 

 

 源代码:

import pandas as pd
import codecs

pd.set_option('display.width', 1000)
pd.set_option('colheader_justify', 'center')
xd = pd.ExcelFile('table_2018.xlsx')
df = xd.parse()

pd.set_option('colheader_justify', 'center')

#设置html文件格式
html_string = '''
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<link rel="stylesheet" type="text/css" href="df_style.css"/>
<body>
{table}
</body>
</html>.
'''
with open('table_2018.html', encoding='utf-8', mode='w') as f:
f.write(html_string.format(table=df.to_html()))

转化后的html文件:

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM