Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

335
Visualizações
Using loop to add to docx.js Document

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 
        ]
      }
    ]
  });
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda