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

163
Visualizações
Word document generation failed when exporting html to .doc/.docx using javascript
  let style=   "<style>  @page {size:29.7cm 21cm; mso-page-orientation:landscape; margin: 1.2cm 1.2cm 1.2cm 1.2cm; } @page Section1 { } div.Section1 {page:Section1 ;} </style>";

  var 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'><head>"+ "<meta charset='UTF-8'>"+ style+"</head><body>";
  var footer = "</body></html>";
  let memo_html =  await this.GetMemo_html() ;

  var blob = new Blob(["\ufeff", html], {
    type: "application/msword",
  });

  // Specify link url
  var url =
    "data:application/vnd.ms-word;charset=utf-8," +
    encodeURIComponent(html);

  // Specify file name
  let filename = "NewspaperAddMemo.docx";

  // Make download link element
  var filefulldlink = document.createElement("a");

  document.body.appendChild(filefulldlink);

  if (navigator.msSaveOrOpenBlob) {
    navigator.msSaveOrOpenBlob(blob, filename);
  } else {
    // Make a link to the file
    filefulldlink.href = url;

    // Setting the file name
    filefulldlink.download = filename;

    //triggering the function
    filefulldlink.click();
  }

  document.body.removeChild(filefulldlink);

sometimes when I export html code to word document , this kind of failed documet get generated.enter image description here But sometimes correct file get exported.enter image description here But these two are different html codes. But,When I generate a pdf file from html code , it always works fine. so, nothing wrong with the html code. I even tried copying the html code in w3schools editor and nothing wrong with the html code.

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