1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python另存为excel_在Python中将Excel另存为HTML

python另存为excel_在Python中将Excel另存为HTML

时间:2020-01-05 07:26:59

相关推荐

python另存为excel_在Python中将Excel另存为HTML

我正在尝试使用win32com.client将现有的Excel文件保存为

Python格式的HTML.下面是我的代码和生成的错误消息.有什么建议?

import win32com.client as win32

excel = win32.gencache.EnsureDispatch('Excel.Application')

wb = excel.Workbooks.Open(r'D:\eclipse\test.xlsx')

excel.Visible = True

ws = wb.Worksheets('Sheet1')

ob = wb.PublishObjects.Add(1,'C:\test.html','Sheet1')

ob.Publish(True)

使用以下Traceback:

Traceback (most recent call last):

File "D:\eclipse\DMS\AGADMS\exceltohtml.py", line 21, in

ob = wb.PublishObjects.Add(1,'C:\test.html')

File "C:\Python34\lib\site-packages\win32com\gen_py\00020813-0000-0000-C000-000000000046x0x1x7\PublishObjects.py", line 37, in Add

, Title)

_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2146827284), None)

最佳答案 熊猫对此非常好.

使用pandas应该为您简化这一点.见下文:

import pandas as pd

wb = pd.read_excel('D:\eclipse\test.xlsx') # This reads in your excel doc as a pandas DataFrame

wb.to_html('C:\test.html') # Export the DataFrame (Excel doc) to an html file

Excel输入示例:

示例html输出:

希望这可以帮助.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。