xxxxxxxxxx
import pandas as pd
# read the Excel file
df = pd.read_excel('input.xlsx')
# convert DataFrame to JSON
json_data = df.to_json(orient='records')
print(json_data)
xxxxxxxxxx
import pandas as pd
# Assuming the JSON data is stored in a file called 'data.json'
json_file = 'data.json'
# Load the JSON data into a pandas DataFrame
data_frame = pd.read_json(json_file)
# Convert the DataFrame to an Excel file
excel_file = 'data.xlsx'
data_frame.to_excel(excel_file, index=False)
xxxxxxxxxx
import pandas as pd
# Replace 'path_to_excel_file' with the actual path to your Excel file
data_frame = pd.read_excel('path_to_excel_file.xlsx')
# Convert the data frame to JSON and specify the orientation as 'records'
json_data = data_frame.to_json(orient='records')
print(json_data)
xxxxxxxxxx
function main(workbook: ExcelScript.Workbook): TableData[] {
// Get the first table in the "WithHyperLink" worksheet.
// If you know the table name, use `workbook.getTable('TableName')` instead.
const table = workbook.getWorksheet('WithHyperLink').getTables()[0];
// Get all the values from the table as text.
const range = table.getRange();
// Create an array of JSON objects that match the row structure.
let returnObjects: TableData[] = [];
if (table.getRowCount() > 0) {
returnObjects = returnObjectFromValues(range);
}
// Log the information and return it for a Power Automate flow.
console.log(JSON.stringify(returnObjects));
return returnObjects
}
function returnObjectFromValues(range: ExcelScript.Range): TableData[] {
let values = range.getTexts();
let objectArray : TableData[] = [];
let objectKeys: string[] = [];
for (let i = 0; i < values.length; i++) {
if (i === 0) {
objectKeys = values[i]
continue;
}
let object = {}
for (let j = 0; j < values[i].length; j++) {
// For the 4th column (0 index), extract the hyperlink and use that instead of text.
if (j === 4) {
object[objectKeys[j]] = range.getCell(i, j).getHyperlink().address;
} else {
object[objectKeys[j]] = values[i][j];
}
}
objectArray.push(object as TableData);
}
return objectArray;
}
interface TableData {
"Event ID": string
Date: string
Location: string
Capacity: string
"Search link": string
Speakers: string
}