Skip to content

Commit

Permalink
Update convert_excel_to_json.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sangam14 authored Nov 27, 2023
1 parent 6997a47 commit d558a28
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions convert_excel_to_json.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
import sys
import pandas as pd
import json

def convert_excel_to_js(excel_path, js_path):
# Read the Excel file
df = pd.read_excel(excel_path)
# Existing logic to convert Excel to JSON and write to JS

# Convert the DataFrame to a list of dictionaries
data_list = df.to_dict(orient='records')
if __name__ == "__main__":
excel_file_path = sys.argv[1] # First argument
js_file_path = sys.argv[2] # Second argument
convert_excel_to_js(excel_file_path, js_file_path)

# Convert the list of dictionaries to a JSON formatted string
json_data = json.dumps(data_list, indent=2)

# Prepare the content to be written to a JS file
js_content = f"const entries = {json_data};\n"

# Write the JSON data to a .js file with a JavaScript variable assignment
with open(js_path, 'w') as js_file:
js_file.write(js_content)

print(f"Data has been written to {js_path}")

# The paths to the Excel file and the output JS file
excel_file_path = './cloudnativetools.xlsx' # Replace with your actual Excel file path
js_file_path = 'entries.js' # Replace with your desired JS file path

# Run the conversion
convert_excel_to_js(excel_file_path, js_file_path)

0 comments on commit d558a28

Please sign in to comment.