1

Есть ли библиотека с помощью которой можно генерировать файлы docx на клиенте, без node js

1 ответ 1

3

Например, docx.js

документация - https://docx.js.org/api/

const generate = () => {
  const doc = new Document();

  const paragraph = new Paragraph("Hello World");
  const text1 = new TextRun("Foo Bar").bold();
  const text2 = new TextRun("Foo Bar").tab().bold();
  
  paragraph.addRun(text1);
  paragraph.addRun(text2);
  doc.addParagraph(paragraph);

  const packer = new Packer();

  packer.toBlob(doc).then(blob => saveAs(blob, "example.docx"));
}

const button = document.querySelector('button');
button.addEventListener('click', generate);
<script src="https://unpkg.com/docx@4.0.0/build/index.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.8/FileSaver.js"></script>

<button type="button">Click to generate document</button>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.