Skip to content

Instantly share code, notes, and snippets.

@saurabhwahile
Last active August 15, 2023 13:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save saurabhwahile/0ffd8a91462587dae5ade7ef828242d1 to your computer and use it in GitHub Desktop.
Save saurabhwahile/0ffd8a91462587dae5ade7ef828242d1 to your computer and use it in GitHub Desktop.
Script for importing zerodha stocks in xlsx to moneycontrol csv if you want to use moneycontrol terminal
#You'll still have to manually enter dates here, as the xlsx file from zerodha does not show dates(SIP of stocks causes multiple dates)
#EDIT: Usage python zerodha_to_moneycontrol.py <FILENAME>
import sys
from openpyxl import load_workbook
wb = load_workbook(sys.argv[1])
ws = wb.active
csv_list = [["BSE/NSE/ISIN Code","Buy Date","Buy Quantity","Buy Price",]]
curr_row = 15
while True:
data = []
data.append(ws.cell(row=curr_row, column=3).value)
data.append(' ')
data.append(ws.cell(row=curr_row, column=5).value)
data.append(ws.cell(row=curr_row, column=10).value)
data.append('')
csv_list.append(data)
curr_row+=1
if ws.cell(row=curr_row, column=3).value == None:
break
import csv
with open("moneycontrol_upload.csv", "wb") as f:
writer = csv.writer(f)
writer.writerows(csv_list)
@Tejesh-Raut
Copy link

Values as of today

  data = []
  data.append(ws.cell(row=curr_row, column=3).value)
  data.append(' ')
  data.append(ws.cell(row=curr_row, column=5).value)
  data.append(ws.cell(row=curr_row, column=10).value)
  data.append('')

@saurabhwahile
Copy link
Author

Updated! Thanks for the correction...

@aashu4uiit
Copy link

@saurabhwahile do you still maintain this - seems not working now.
python zerodha_to_moneycontrol.py tradebook-VT3693-EQ-2018.xlsx
Traceback (most recent call last):
File "C:\Users\aashi\Downloads\zerodha_to_moneycontrol.py", line 30, in
writer.writerows(csv_list)
TypeError: a bytes-like object is required, not 'str'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment