2

I am trying to add data to an existing excel file, the problem I am facing is that the data is getting imported but the equation and the format is being deleted in original file.

I attached my code below

import xlwt
import xlrd
from xlutils.copy import copy

#open the excel file
rb=xlrd.open_workbook('Voltage_T.xlsx')

#make a writable copy of the opened excel file
wb=copy(rb)

#read the first sheet to write to within the writable copy
w_sheet=wb.get_sheet(0)

#write or modify the value at 2nd row first column
w_sheet.write(0,1,'WWW.GOOGLE.COM')

#the last step saving the work book
wb.save('Voltage_WW.xls')

1 Answer 1

3

You need to set formatting_info to true

rb=xlrd.open_workbook('Voltage_T.xlsx', formatting_info = True)

However xlrd doesn't support xlsx with formatting_info at the moment. So if you really have to use .xlsx you will need another library.

I didn't used it myself so I can't tell you if it's a good library but thanks to a quick search on google XlsxWriter seems to answer your needs.

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

2 Comments

Thanks for the respond, the formatting_info works as you suggested for xls but the equation in the original file is deleted, the formatting is working now. I will give a try to xlsxwriter
Glad to help you ! If it answered your question don't forget to accept this as an answer :)

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.