Преобразование слова HTML в MS с использованием верхнего и нижнего колонтитула с использованием JavaScript - PullRequest
0 голосов
/ 28 июня 2019

enter image description here Я перевожу всю мою HTML-страницу в MS Word. Здесь я попробовал, ссылаясь на эту ссылку ниже:

https://phppot.com/javascript/how-to-export-html-to-word-document-with-javascript/

работает нормально. Но я попытался установить нижний колонтитул, он не рендерит, а показывает текст в нижнем колонтитуле на последней странице. По ссылке: Заголовок HTML-кода Office

function Export2Doc(element, filename = '') {
  $("#export_btn_word").remove();
  var header = "<html xmlns:o='urn:schemas-microsoft-com:office:office' " +
    "xmlns:w='urn:schemas-microsoft-com:office:word' " +
    "xmlns:m='http://schemas.microsoft.com/office/2004/12/omml' " +
    "xmlns='http://www.w3.org/TR/REC-html40'>" +
    "<head><meta http-equiv='Content-Type' content='text/html;charset=utf-8'><title>Export HTML to Word Document with JavaScript</title></head><body>";
  var footer = "<div style='mso-element:footer' id=f1><p class=MsoFooter><span style='mso-tab-count:1'></span><span style='mso-field-code:\" PAGE \"'></span> </p></div>";
  var end = "</div></body></html>";
  var sourceHTML = header + "<div class='Section1'>" + document.getElementById(element).innerHTML + footer + end;

  var source = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(sourceHTML);
  var fileDownload = document.createElement("a");
  document.body.appendChild(fileDownload);
  fileDownload.href = source;
  fileDownload.download = '#form.la_request.RefNo#.doc';
  fileDownload.click();
  document.body.removeChild(fileDownload);
}
p.MsoFooter,
li.MsoFooter,
div.MsoFooter {
  margin: 0in 0in 1in 0in;
  margin-bottom: .0001pt;
  mso-pagination: widow-orphan;
  tab-stops: center 3.0in right 6.0in;
}

.footer {
  font-size: 9pt;
}

@page Section1 {
  size: 8.5in 11.0in;
  margin: 0.5in 0.5in 0.5in 0.5in;
  mso-header-margin: 0.5in;
  mso-header: h1;
  mso-footer: f1;
  mso-footer-margin: 0.5in;
  mso-paper-source: 0;
}

div.Section1 {
  page: Section1;
}
<button id="export_btn_word" onclick="Export2Doc('view_ls_app1_grid_test');">Export as .doc</button>

Пожалуйста, помогите мне!

...