My requirement is that I would get an excel daily with different number of columns each time and I need to display the contents of this excel. Is there a method to convert the Excel's binary data to a record with having a preset structure you need to put this data in?
Any suggestions will be appreciated.
Thanks in Advance.
Regards,
Akash Balamurugan
Hello @Akash Balamurugan ,
To achieve the functionality you're looking for, you'll need to follow these steps:
Here's the script you'll need to use:
````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
function convertExcelToJson(ele) {
try {
const input = document.querySelector("#" + ele + " > input");
const file = input.files[0];
const reader = new FileReader();
reader.onload = (event) => {
let data = new Uint8Array(reader.result);
let work_book = XLSX.read(data, { type: 'array' });
let sheet_name = work_book.SheetNames;
let sheet_data = XLSX.utils.sheet_to_json(work_book.Sheets[sheet_name[0]], { header: 1 });
if (sheet_data.length > 0) {
let table_output = '';
for (let row = 0; row < sheet_data.length; row++) {
table_output += '';
for (let cell = 0; cell < sheet_data[row].length; cell++) {
if (row == 0) {
table_output += '' + sheet_data[row][cell] + '';
} else {
}
document.getElementById($parameters.ContainerId).innerHTML = table_output;
};
reader.readAsArrayBuffer(file);
} catch (error) {
$reject(error.me)
convertExcelToJson($parameters.File_Input)
```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
Parameters:
$parameters.File_Input: The parameter that holds the ID of the file input element.
$parameters.ContainerId: The parameter that holds the ID of the container where the table will be displayed.
Optional Styling:
You can add custom CSS classes to the generated table for styling purposes. Just modify the
<table>, <th>, and <td> tags in the table_output string to include your class names
Remember to replace $parameters.File_Input and $parameters.ContainerId with the actual IDs used in your project.
Hi @Akash Balamurugan ,
You just need to show excel data only or there is search functionality and sorting as well with the data?
It would be a good start to first show data only.
for showing excel with dynamic columns I would suggest you to convert your excel sheet into HTML table then use those table directly into web page.
There are some forge component which can convert excel into html table.
Find link of them below:
https://www.outsystems.com/forge/component-overview/17889/excel2html-o11
This component built in traditional and it's created using javascript so you can use this javascript in reactive as well.
And you can use this service action-
https://www.outsystems.com/forge/component-overview/10779/excel-to-html-o11
Thanks
Hi @Akash Balamurugan,
Please refer attached OML. You get some idea.
I have a question: do we know all the columns from the excel or it can be any dynamic columns?
It can be dynamic like for eg. one day i might get 5 columns and the day after that i could get 8 which also may include the previous days 5 or not.
In the Oml you have sent there is a entity "ExcelRecords" that is used as record definition i need to get the data with out that record definition.