I am using docx.js to create a Word document from text that is entered into a textarea. I have created an array (arrayOfLines) which splits the textarea contents at each new line.
I now want to add this array to the Document using a loop function, and the code I am using does not seem to work. Hoping someone might be able to help, as I could not find many answers here so far. Apologies if I haven't been clear, this is my first question. Thank you.
saveEssay () {
var arrayOfLines = document.getElementById('textArea').value.split('\n');
const buildParagraph = async()=>{
let paragraphArray = []
for (var i = 0; i < arrayOfLines.length; i++){
paragraphArray.push(new Paragraph({text: arrayOfLines[i].text }))
}
return paragraphArray;
};
let doc = new Document({
sections: [
{
headers: {
default: new Header({
children: [new Paragraph("Page heading")],
}),
},
children: [
new Paragraph({ text: "My Essay", heading: HeadingLevel.HEADING_2 }),
buildParagraph() // paragraphs are not coming through
]
}
]
});
}