How to export text entries to a Word document
Hi all.
I was looking for how to export Storyline text entries to Word here on E-Learning Heroes, but even though there has been a bit of discussion about it over the years, I couldn't find a solution. Please forgive me if someone has posted one – I couldn't find it.
Anyway, I've got a solution to share (it was actually a collaboration between myself and my son with bits and pieces we grabbed off the internet). You can paste the javascript as it is below but, depending on how you want the final Word doc to look, you may need to make some modifications.
I've included comments in the javascript, which hopefully makes sense as to which bits you might want to change.
I've also attached a couple of different story files as examples showing how you can customise the output.
I hope this is useful!
Cheers, Craig
var player = GetPlayer();
// ADD ANY GLOBAL CSS HERE - I have changed the font to Calibri and set the white-space to allow for line breaks
var HtmlHead = "<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'><head><meta charset='utf-8'><style>body {font-family: Calibri, Arial, sans-serif; white-space: pre;}</style></head><body>";
var EndHtml = "</body></html>";
// ENTER YOUR HTML/CONTENT HERE - use strings for tags and player.GetVar for the Storyline variables
var html = HtmlHead +
"<h1>Activity 1</h1>"
+ player.GetVar("TextEntry")
+ EndHtml;
//This specifies the type
var blob = new Blob(['\ufeff', html], {
type: 'application/msword'
});
// This specifies the link url
var url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(html);
// SPECIFY THE FILE NAME HERE
filename = 'DocumentName.doc';
// This specifies the download link element
var downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);
if(navigator.msSaveOrOpenBlob ){
navigator.msSaveOrOpenBlob(blob, filename);
}else{
// This sets the link to the file
downloadLink.href = url;
// This sets the file name
downloadLink.download = filename;
// This triggers the function
downloadLink.click();
}