Skip to content

Instantly share code, notes, and snippets.

@saurabhwahile
Last active November 5, 2024 15:57
Show Gist options
  • 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)
@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'

@kunalGuptaX
Copy link

Updated format as of November 2024:

#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 = [["ISIN Code","Enter Full/Partial Stock Name","Date","Transaction Type (Enter Either Buy or Sell)","Exchange", "Qty", "Purchase/Sell price per share"]]

curr_row = 15

while True:
  data = []
  data.append(ws.cell(row=curr_row, column=3).value)
  data.append(ws.cell(row=curr_row, column=2).value)
  data.append(ws.cell(row=curr_row, column=4).value)
  data.append(ws.cell(row=curr_row, column=8).value)
  data.append(ws.cell(row=curr_row, column=5).value)
  data.append(ws.cell(row=curr_row, column=10).value)
  data.append(ws.cell(row=curr_row, column=11).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", "w") as f:
    writer = csv.writer(f)
    writer.writerows(csv_list)

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