How to use formula in sheet_to_html ? #3110

Open
opened 2024-04-14 23:47:39 +00:00 by manutheblacker · 0 comments

I'm using the visual excel editor x-data-spreasheets into my app for the moment.
I've been able to use xtos with sheet_to_html right now to display saved data from the db.

The issue I'm encountering is with formula, I would like in case a formula is present into the html table row, the formula and his related calculation be applied.

Here is my code :

<div id="tavolo"></div>
                   var obsheets = [
            {
                "name": "Sheet1",
                "freeze": "A1",
                "styles": [],
                "merges": [],
                "rows": {
                    "0": {
                        "cells": {
                            "0": {
                                "text": "Name"
                            },
                            "1": {
                                "text": "Index"
                            }
                        }
                    },
                    "1": {
                        "cells": {
                            "0": {
                                "text": "Bill Clinton"
                            },
                            "1": {
                                "text": "42"
                            }
                        }
                    },
                    "2": {
                        "cells": {
                            "0": {
                                "text": "GeorgeW Bush"
                            },
                            "1": {
                                "text": "43"
                            }
                        }
                    },
                    "3": {
                        "cells": {
                            "0": {
                                "text": "Barack Obama"
                            },
                            "1": {
                                "text": "44"
                            }
                        }
                    },
                    "4": {
                        "cells": {
                            "0": {
                                "text": "Donald Trump"
                            },
                            "1": {
                                "text": "=b2+b3"
                            }
                        }
                    },
                    "5": {
                        "cells": {
                            "0": {
                                "text": "Joseph Biden"
                            },
                            "1": {
                                "text": "46"
                            }
                        }
                    },
                    "len": 6
                },
                "cols": {
                    "len": 26
                },
                "validations": [],
                "autofilter": {}
            }]
            let workbook = xtos(obsheets);   
         let output = [];
        for( var er in workbook.SheetNames ) {
            //workbook.SheetNames.forEach(name => {
            var name = workbook.SheetNames[er];
            const worksheet = workbook.Sheets[name];
            const html = XLSX.utils.sheet_to_html(worksheet);     
            /* add a header with the title name followed by the table */
            output.push(`<H3>${name}</H3>${html}`);
        };
        /* write to the DOM at the end */
        tavolo.innerHTML = output.join("\n");

I was thinking to override the method sheet_to_html, but in other to achieve what it is the method i can use ?

I'm using the visual excel editor [x-data-spreasheets](https://github.com/myliang/x-spreadsheet) into my app for the moment. I've been able to use xtos with sheet_to_html right now to display saved data from the db. The issue I'm encountering is with formula, I would like in case a formula is present into the html table row, the formula and his related calculation be applied. Here is my code : ```html <div id="tavolo"></div> ``` ```js var obsheets = [ { "name": "Sheet1", "freeze": "A1", "styles": [], "merges": [], "rows": { "0": { "cells": { "0": { "text": "Name" }, "1": { "text": "Index" } } }, "1": { "cells": { "0": { "text": "Bill Clinton" }, "1": { "text": "42" } } }, "2": { "cells": { "0": { "text": "GeorgeW Bush" }, "1": { "text": "43" } } }, "3": { "cells": { "0": { "text": "Barack Obama" }, "1": { "text": "44" } } }, "4": { "cells": { "0": { "text": "Donald Trump" }, "1": { "text": "=b2+b3" } } }, "5": { "cells": { "0": { "text": "Joseph Biden" }, "1": { "text": "46" } } }, "len": 6 }, "cols": { "len": 26 }, "validations": [], "autofilter": {} }] let workbook = xtos(obsheets); let output = []; for( var er in workbook.SheetNames ) { //workbook.SheetNames.forEach(name => { var name = workbook.SheetNames[er]; const worksheet = workbook.Sheets[name]; const html = XLSX.utils.sheet_to_html(worksheet); /* add a header with the title name followed by the table */ output.push(`<H3>${name}</H3>${html}`); }; /* write to the DOM at the end */ tavolo.innerHTML = output.join("\n"); ``` I was thinking to override the method sheet_to_html, but in other to achieve what it is the method i can use ?
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#3110
No description provided.