I use the xlsx.js library for converting excel-files to json and it works, but I have a problem when I add a hyperlink into a cell of the table as it's illustrated in the image below:
The code I use for parsing:
function readExcel(url) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.responseType = "arraybuffer";
if (xmlhttp.overrideMimeType) {
xmlhttp.overrideMimeType('text/plain; charset=x-user-defined');
}
xmlhttp.onload = function(e) {
var arraybuffer = xmlhttp.response;
var data = new Uint8Array(arraybuffer);
var arr = new Array();
for (var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
var wb = XLSX.read(arr.join(""), { type: "binary" });
// var sheet_name_list = wb.SheetNames;
wb.SheetNames.forEach((sheetName, index) => {
let jsonObject = XLSX.utils.sheet_to_json(wb.Sheets[sheetName], { header: 1, raw: true })
console.log("jsonObject", jsonObject)
createTable(jsonObject, index);
});
};
xmlhttp.send();
}
The current output:
[
[
"FirstName",
"LastName",
"Age",
"Country"
],
[
"Alessio",
"",
23,
"Italia"
],
[
"Mauro",
"Doe",
34,
"Germania"
],
...............
]
The problem is on Germania the hyperlink isn't present - How can I solve this problem?

Great question! The
xlsxlibrary doesn't seem to support this out of the box, but luckily it does provide a very simplistic structure of the sheet that we can interact with before converting to JSON.The structure of each cell object is based on its content, all possible cell properties can be found in the Cell Object section of the
xlsxdocumentation.In the documentation, we can see that hyperlinks are stored in the
lkey of the cell object.To access this, we need to do so before converting the sheet data to JSON.
In your original question, the workbook object can be found at
wb.Sheets[sheetName]. If we log this value out prior to converting it to JSON, it would look something like this:As you can see, in cell
D3anlkey is included because the cell is formatted as a hyperlink. The actual hyperlink value can be found inside ofTargetwithin thelobject.Instead of creating our own parser to convert this data to JSON, all we need to do is modify the original workbook object and then convert it to JSON after the fact.
First, we get a list of all of the cells by using
Object.keys()and then can loop over that list to check if a hyperlink is present or not in the current cell.If a hyperlink is present, we will overwrite the
vkey inside of the workbook object for that cell which usually represents therawvalue from the cell.Once we've overwritten the
vkey with the hyperlink values, we can then convert the sheet to JSON like usual.Our result should now come out looking something like this: