-1

I want to replace the names of the rows in my excel sheet. Whatever the row names may be, I have to replace them with:

  1. Street
  2. City
  3. State
  4. Zip

I am able to read the row names. Can anybody help me with replacing the names I read. Here is my piece of code. Thanks

import xlrd

workbook = xlrd.open_workbook('Path to Excel File')
sheet = workbook.sheet_by_index(0)
print(sheet)

for value in sheet.row_values(0):
  print(value)
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241
PowerToYou
  • 23
  • 9
  • Have you seen [this](https://stackoverflow.com/questions/26957831/edit-existing-excel-workbooks-and-sheets-with-xlrd-and-xlwt)? – nostradamus Jul 27 '17 at 14:42
  • Possible duplicate of [Edit existing excel workbooks and sheets with xlrd and xlwt](https://stackoverflow.com/questions/26957831/edit-existing-excel-workbooks-and-sheets-with-xlrd-and-xlwt) – George Alexandria Jul 27 '17 at 17:39

1 Answers1

1
from openpyxl import load_workbook
wb = load_workbook('filename.xlsx')
ws = wb['sheetname']
ws.cell(row=1,column=1).value = 'Street'
ws.cell(row=1,column=2).value = 'City'
ws.cell(row=1,column=3).value = 'State'
ws.cell(row=1,column=4).value = 'Zip'
wb.save('filename.xlsx')
bigbounty
  • 16,526
  • 5
  • 37
  • 65