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