繁体   English   中英

在python中将现有工作表另存为html

[英]saving an existing worksheet as html in python

我浏览了这些链接以及xlwt,xlrd和xlutils 使用xlwt写入现有工作簿的其他链接

from xlutils.copy import copy    
from xlrd import open_workbook    
from xlwt import easyxf    
rb = open_workbook('example.xls',formatting_info=True)    
r_sheet = rb.sheet_by_index(0)    
print r_sheet    
print r_sheet.name    
wb = copy(rb)    
w_sheet = wb.get_sheet(0)    
print w_sheet.name    
w_sheet.save('example.html')    #it throws an error in the last line saying "AttributeError: 'Worksheet' object has no attribute 'save'"

如何使用python将工作表单独保存为HTML文件

我不确定您是否可以仅使用xlwt或xlrd将Excel工作表另存为html。

一种选择是使用熊猫,该熊猫在内部使用xlrd和xlwt,从而使您无需编写所有涉及的步骤。

您可以使用以下内容阅读Excel工作表

df = pandas.read_excel('example.xls', sheetname='sheet1')

并通过以下方式将其获取为html:

html = df.to_html()

html是可以使用open(myfile, 'w').write(html)保存在文件中的字符串

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM