You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
821 B
Vue

5 months ago
<template>
<div>123</div>
</template>
<script setup>
import { Document, Packer, Paragraph, TextRun } from 'docx';
// 创建文档
const doc = new Document({
sections: [
{
properties: {},
children: [
new Paragraph({
text: 'Hello World',
heading: 'Heading1'
}),
new Paragraph({
text: 'This is a simple DOCX file created using DOCX.js.'
})
]
}
]
});
const download = async (doc) => {
const blob = await Packer.toBlob(doc);
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'document.docx';
// Click the link to download the file
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
// download(doc)
</script>
<style scoped></style>