| 1234567891011121314151617181920212223242526272829303132333435363738 |
- import fs from "fs";
- import path from "path";
- import PizZip from "pizzip";
- const contentTypes = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
- <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
- <Default Extension="xml" ContentType="application/xml"/>
- <Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
- </Types>`;
- const rels = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
- <Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/>
- </Relationships>`;
- const documentXml = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
- <w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
- <w:body>
- <w:p><w:r><w:t>{field_name} 异常检测报告</w:t></w:r></w:p>
- <w:p><w:r><w:t>评估日期:{datatime}</w:t></w:r></w:p>
- <w:p><w:r><w:t>接入风机:{turbine_count} 台;异常风机:{abnormal_count} 台</w:t></w:r></w:p>
- <w:p><w:r><w:t>【自动插入:异常概览图】</w:t></w:r></w:p>
- <w:p><w:r><w:t>【自动插入:风机检测器图表】</w:t></w:r></w:p>
- <w:sectPr/>
- </w:body>
- </w:document>`;
- const zip = new PizZip();
- zip.file("[Content_Types].xml", contentTypes);
- zip.file("_rels/.rels", rels);
- zip.file("word/document.xml", documentXml);
- const outDir = path.join(process.cwd(), "templates");
- fs.mkdirSync(outDir, { recursive: true });
- const outPath = path.join(outDir, "anomaly-report-template.docx");
- fs.writeFileSync(outPath, zip.generate({ type: "nodebuffer" }));
- console.log("created:", outPath);
|