-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
6 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |