Analyst
Analyst

Reputation: 137

Add new rows to existing column of excel in python

enter image description here

I want to add new records every week to this existing file without creating a new one.

For example, Next I want to add record on date 6/13/2016

Randy->(13,23,13)

Shaw->(13,15,13)

and many such entries next two months. How do I do that? I am beginner so having trouble to put it in syntax.

I could do only this much

import xlrd

#Opening the excel file
file_location= "C:/Users/agodgh1a/Desktop/Apurva/EPSON.xlsx"
workbook= xlrd.open_workbook(file_location)
sheet=workbook.sheet_by_index(0)

Thank you!

Upvotes: 0

Views: 3982

Answers (2)

Aman Raparia
Aman Raparia

Reputation: 491

xlrd 

is for reading operations only. Since you want perform a write operation use xlwt python module.

Refer to xlwt docs for the same

Upvotes: 1

keredson
keredson

Reputation: 3088

The lib you're using looks like it only reads, not edits. Here's an example in openpyxl:

from openpyxl import Workbook, load_workbook

# create the file
wb = Workbook()
ws = wb.active
ws.append([1, 2, 3])
wb.save("sample.xlsx")

# re-open and append
wb = load_workbook("sample.xlsx")
ws = wb.active
ws.append([4, 5, 6])
wb.save("sample.xlsx")

Run that and you'll have a file sample.xlsx with both rows.

Upvotes: 2

Related Questions