export React to word - hyperLink to place in the same document

Viewed 402

I created word files by simple js code, that convert react to html and download it

let HTMLContent = exportToWord(simulator, options);
const dir = "ltr";
const docTitle = simulator.name;
const header =
  `<html xmlns:o='urn:schemas-microsoft-com:office:office'` +
  ` xmlns:w='urn:schemas-microsoft-com:office:word' ` +
  `xmlns='http://www.w3.org/TR/REC-html40' dir=\"${dir}\"> ` +
  `<head><style>
        </style><meta charset='utf-8'><title>${docTitle}</title></head><body>`;
const footer = "</body></html>";
const sourceHTML = `${header}${HTMLContent}${footer}`;
const source = `data:application/vnd.ms-word;charset=utf-8,${encodeURIComponent(
  sourceHTML
)}`;
const fileDownload = document.createElement("a");
document.body.appendChild(fileDownload);
fileDownload.href = source;
fileDownload.download = `${docTitle}.doc`;
fileDownload.click();
document.body.removeChild(fileDownload);

The files are created and everything works well. The problem is that I want to create links within the file to another location in the word document How can I do it?

0 Answers
Related