0

I went through these link and other links for xlwt, xlrd and xlutils writing to existing workbook using 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'"

How can I save the worksheet alone as HTML file uing python

1
  • You are trying to use an xlrd Book class instance to save. From the xlrd description in the docs: This package is for reading data and formatting information from Excel files.. The Book class does NOT have a save method. Commented Oct 27, 2013 at 17:18

1 Answer 1

1

I am not sure you can save and excel sheet as html just with xlwt or xlrd.

One alternative is to use pandas which internally uses xlrd and xlwt saving you of coding all the steps involved.

You can read your excel sheet with

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

and get it as html with:

html = df.to_html()

html is a string you can save in a file with open(myfile, 'w').write(html)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.