It sounds best suited to use a dictionary
to map the values from: to
. This seems to be what you've described:
from xlrd import open_workbook
from xlutils.copy import copy
import xlsxwriter
rb = open_workbook("Workbook1.xlsx")
# Create an new Excel file and add a worksheet.
wb = xlsxwriter.Workbook('Updated_Workbook1.xlsx')
ws = wb.add_worksheet()
s_orig = rb.sheet_by_index(0)
LVdemact = {'Home1': 1234, 'Home2': 435, 'Home3': 346, 'Home4': 768, 'Home5': 876}
for row in range(s_orig.nrows):
for col in range(s_orig.ncols):
if s_orig.cell(row,col).value in LVdemact:
# s.write(row, col, LVdemact[item])
ws.write(row, col, LVdemact[s_orig.cell(row,col).value])
else:
ws.write(row, col, s_orig.cell(row,col).value)
wb.close()
Original:
Modified:
