- html-docx-js
const image = '<style>image{width:100%}</style>';
const htmlHead = `<head><meta charset="UTF-8" />${image}</head>`;`
const htmlBody = `<body>${getHtml.main}</body>`;
const htmlTemplate = `<!doctype html><html lang="en" class="downLoad">${htmlHead + htmlBody}</html>`;
let htmlTemplateNew = htmlTemplate.replaceAll(' ', ' ');
htmlTemplateNew = htmlTemplate.replaceAll('\n', '<br/>');
htmlTemplateNew = htmlTemplateNew.replaceAll(
`width="${554}" height="1">', 'width="620" height="1">`,
'',
);
// 文件流,用来保存本地
const converted = window.htmlDocx.asBlob(htmlTemplateNew, {
mimeType:
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
header: getHtml.header,
footer: getHtml.footer,
});
- docx.js
export default function (command: Command, callback) {
return function (options: IExportDocxOption) {
const { fileName } = options;
const {
data: { header, main, footer },
} = command.getValue();
const doc = new Document({
sections: [
{
headers: {
default: new Header({
children: convertElementListToDocxChildren(header || []),
}),
},
footers: {
default: new Footer({
children: convertElementListToDocxChildren(footer || []),
}),
},
children: convertElementListToDocxChildren(main || []),
},
],
});
Packer.toBlob(doc).then((blob) => {
// saveAs(blob, `${fileName}.docx`);
callback(blob);
});
// Packer.toBuffer(doc).then((buffer) => {
// callback(buffer);
// });
};
}