Question

I want to parse an xlsx file which contains hyperlinks on my node.js server. I tried some xlsx parser in npm (like 'excel-parser', 'xlsx'), but I couldn't get the hyperlink values (only the text value). Does anyone knows how to extract the hyperlink using node.js ?

Was it helpful?

Solution

If you dislike the existing solutions, you can always unzip the file (OfficeOpen XML files are zipped directories with sereval files in it), and parse the main part yourself in the search of links.

OTHER TIPS

An old question, but one without an answer that I could easily find elsewhere after half an hour of looking.

The below code will read an XSLX and dump it to the console row by row: row.values will be plain text or an object with keys formula and result, the former being the hyperlink, the latter the visible text.

I've only just found exceljs so ymmv, but it seems straightforward and has a large, but not overwhelming, variety of options for getting the job done quickly.

const xl = require('exceljs');
const csvPath = 'NTA Transcripts.xlsx';
const workbook = new xl.Workbook();
await workbook.xlsx.readFile(csvPath);
const worksheet = workbook.getWorksheet(1);
worksheet.eachRow({ includeEmpty: true }, (row, rowNumber) => {
  console.log("Row ", rowNumber, ": ", JSON.stringify(row.values, null, 2));
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top