I am trying to import the data and create a new excel file first and then I want to add this excel sheet to an existing Excel file.
I did the first step as successfully as follows and I am stuck in doing the second step of adding the new sheet to another existing excel file.
I wish to keep the same existing formatting including the existing formulas in my existing excel sheet. Any help, please? I tried a lot with existing help but all refer to using Pandas for both the files. But in my case, the existing excel file has nothing to do with Pandas data structure since it has many formulas and texts formatted.
from openpyxl import load_workbook
import json
from pprint import pprint
import pandas as pd
data = json.load(open('data.txt'))
# Create a Pandas dataframe from the data.
df = pd.DataFrame({'Data': data["_owner"]["_accountId"]["averageIRR"]},index=["averageIRR"])
# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('data_sheet.xlsx', engine='xlsxwriter')
# Convert the dataframe to an XlsxWriter Excel object.
df.to_excel(writer, sheet_name='Sheet1')
# Close the Pandas Excel writer and output the Excel file.
writer.save()
The data file is as below:
{
"_id": "58edf90",
"_owner": {
"_id": "57e4611f3a",
"_accountId": {
"_id": "57e294611f3b",
"companyName": "authguys",
"averageIRR": 0
}
}
}