springboot + vue 导出word 试卷

1、需求说明

项目中有涉及到考试,做题的需求,要求导入word试题,试题带有公式,excel 也需要导入。当然了,有导入也会有导出,生成一张试卷的时候,需要将试卷导出成word 进行打印。试题当然是个列表,有如下几个参数。

  • 试卷名称
  • 试卷的题型
  • 题干
  • 分值
  • 选项(多个)
  • 正确答案
  • 知识点
  • 标签

2、准备工作

  • 制作你想要的word 模板

  • 另存为word为wordxml 文档

  • 将xml文件拷贝至编辑器中,博主放在了resource\word目录下,当然你可以随便找个地方放。格式化代码

  • 将文件后缀改成ftl

找到对应的文字描述信息,将上诉定义好的参数,用${字段名称}替换,博主这里循环了三次,试题循环、题目循环、选项循环

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<pkg:package xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage">
    <pkg:part pkg:name="/_rels/.rels" pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
        <pkg:xmlData>
            <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
                <Relationship Id="rId4"
                              Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
                              Target="word/document.xml"/>
                <Relationship Id="rId2"
                              Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
                              Target="docProps/core.xml"/>
                <Relationship Id="rId1"
                              Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties"
                              Target="docProps/app.xml"/>
                <Relationship Id="rId3"
                              Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties"
                              Target="docProps/custom.xml"/>
            </Relationships>
        </pkg:xmlData>
    </pkg:part>
    <pkg:part pkg:name="/word/_rels/document.xml.rels"
              pkg:contentType="application/vnd.openxmlformats-package.relationships+xml">
        <pkg:xmlData>
            <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
                <Relationship Id="rId5"
                              Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable"
                              Target="fontTable.xml"/>
                <Relationship Id="rId4"
                              Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/customXml"
                              Target="../customXml/item1.xml"/>
                <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme"
                              Target="theme/theme1.xml"/>
                <Relationship Id="rId2"
                              Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings"
                              Target="settings.xml"/>
                <Relationship Id="rId1"
                              Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles"
                              Target="styles.xml"/>
            </Relationships>
        </pkg:xmlData>
    </pkg:part>
    <pkg:part pkg:name="/word/document.xml"
              pkg:contentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml">
        <pkg:xmlData>
            <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
                        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                        xmlns:o="urn:schemas-microsoft-com:office:office"
                        xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
                        xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
                        xmlns:v="urn:schemas-microsoft-com:vml"
                        xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
                        xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
                        xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
                        xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
                        xmlns:w10="urn:schemas-microsoft-com:office:word"
                        xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
                        xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
                        xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
                        xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
                        xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
                        xmlns:wpsCustomData="http://www.wps.cn/officeDocument/2013/wpsCustomData"
                        mc:Ignorable="w14 w15 wp14">
                <w:body>
                    <w:p>
                        <w:pPr>
                            <w:pStyle w:val="3"/>
                            <w:bidi w:val="0"/>
                            <w:jc w:val="center"/>
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                <w:b/>
                                <w:bCs/>
                                <w:szCs w:val="36"/>
                                <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                            </w:rPr>
                        </w:pPr>
                        <w:bookmarkStart w:id="0" w:name="_GoBack"/>
                        <w:bookmarkEnd w:id="0"/>
                        <w:r>
                            <w:rPr>
                                <w:rFonts w:hint="eastAsia"/>
                                <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                            </w:rPr>
                            <w:t>${testPaperName}</w:t>
                        </w:r>
                    </w:p>
                    <#list testPaperList as t>
                        <w:p>
                            <w:pPr>
                                <w:pStyle w:val="4"/>
                                <w:bidi w:val="0"/>
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                    <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                </w:rPr>
                            </w:pPr>
                            <w:r>
                                <w:rPr>
                                    <w:rFonts w:hint="eastAsia"/>
                                    <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                </w:rPr>
                                <w:t>${t.type}(共${t.cnt}题,${t.sumScore}分)</w:t>
                            </w:r>
                        </w:p>
                        <#list t.sysExamQuestions as e>
                            <w:p>
                                <w:pPr>
                                    <w:keepNext w:val="0"/>
                                    <w:keepLines w:val="0"/>
                                    <w:pageBreakBefore w:val="0"/>
                                    <w:widowControl w:val="0"/>
                                    <w:kinsoku/>
                                    <w:wordWrap/>
                                    <w:overflowPunct/>
                                    <w:topLinePunct w:val="0"/>
                                    <w:autoSpaceDE/>
                                    <w:autoSpaceDN/>
                                    <w:bidi w:val="0"/>
                                    <w:adjustRightInd/>
                                    <w:snapToGrid/>
                                    <w:spacing w:line="360" w:lineRule="auto"/>
                                    <w:textAlignment w:val="auto"/>
                                    <w:rPr>
                                        <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                        <w:sz w:val="24"/>
                                        <w:szCs w:val="24"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                        <w:sz w:val="24"/>
                                        <w:szCs w:val="24"/>
                                    </w:rPr>
                                    <w:t>${e.questionContent}</w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                        <w:color w:val="FF0000"/>
                                        <w:sz w:val="24"/>
                                        <w:szCs w:val="24"/>
                                        <w:lang w:eastAsia="zh-CN"/>
                                    </w:rPr>
                                    <w:t>(</w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                        <w:color w:val="FF0000"/>
                                        <w:sz w:val="24"/>
                                        <w:szCs w:val="24"/>
                                        <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                    </w:rPr>
                                    <w:t>${e.score}分</w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                        <w:color w:val="FF0000"/>
                                        <w:sz w:val="24"/>
                                        <w:szCs w:val="24"/>
                                        <w:lang w:eastAsia="zh-CN"/>
                                    </w:rPr>
                                    <w:t>)</w:t>
                                </w:r>
                            </w:p>
                            <#list e.answerData as a>
                                <w:p>
                                    <w:pPr>
                                        <w:keepNext w:val="0"/>
                                        <w:keepLines w:val="0"/>
                                        <w:pageBreakBefore w:val="0"/>
                                        <w:widowControl w:val="0"/>
                                        <w:kinsoku/>
                                        <w:wordWrap/>
                                        <w:overflowPunct/>
                                        <w:topLinePunct w:val="0"/>
                                        <w:autoSpaceDE/>
                                        <w:autoSpaceDN/>
                                        <w:bidi w:val="0"/>
                                        <w:adjustRightInd/>
                                        <w:snapToGrid/>
                                        <w:spacing w:line="360" w:lineRule="auto"/>
                                        <w:textAlignment w:val="auto"/>
                                        <w:rPr>
                                            <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                            <w:sz w:val="24"/>
                                            <w:szCs w:val="24"/>
                                            <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                        </w:rPr>
                                    </w:pPr>
                                    <w:r>
                                        <w:rPr>
                                            <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                            <w:sz w:val="24"/>
                                            <w:szCs w:val="24"/>
                                        </w:rPr>
                                        <w:t>${a.optionsName}、${a.optionsContent}</w:t>
                                    </w:r>
                                </w:p>
                            </#list>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:rFonts w:hint="eastAsia"/>
                                        <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                        <w:color w:val="808080" w:themeColor="text1" w:themeTint="80"/>
                                        <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                        <w14:textFill>
                                            <w14:solidFill>
                                                <w14:schemeClr w14:val="tx1">
                                                    <w14:lumMod w14:val="50000"/>
                                                    <w14:lumOff w14:val="50000"/>
                                                </w14:schemeClr>
                                            </w14:solidFill>
                                        </w14:textFill>
                                    </w:rPr>
                                    <w:t>正确答案:</w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                        <w:color w:val="FF0000"/>
                                        <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                    </w:rPr>
                                    <w:t>(${e.questionRight})</w:t>
                                </w:r>
                            </w:p>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:rFonts w:hint="default"/>
                                        <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                        <w:color w:val="808080" w:themeColor="text1" w:themeTint="80"/>
                                        <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                        <w14:textFill>
                                            <w14:solidFill>
                                                <w14:schemeClr w14:val="tx1">
                                                    <w14:lumMod w14:val="50000"/>
                                                    <w14:lumOff w14:val="50000"/>
                                                </w14:schemeClr>
                                            </w14:solidFill>
                                        </w14:textFill>
                                    </w:rPr>
                                    <w:t>知识点:</w:t>
                                </w:r>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                        <w:color w:val="FF0000"/>
                                        <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                    </w:rPr>
                                    <w:t>${e.analysis}</w:t>
                                </w:r>
                            </w:p>
                            <w:p>
                                <w:pPr>
                                    <w:rPr>
                                        <w:rFonts w:hint="default"/>
                                        <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                    </w:rPr>
                                </w:pPr>
                                <w:r>
                                    <w:rPr>
                                        <w:rFonts w:hint="eastAsia" w:ascii="仿宋" w:hAnsi="仿宋" w:eastAsia="仿宋" w:cs="仿宋"/>
                                        <w:color w:val="808080" w:themeColor="text1" w:themeTint="80"/>
                                        <w:lang w:val="en-US" w:eastAsia="zh-CN"/>
                                        <w14:textFill>
                                            <w14:solidFill>
                                                <w14:schemeClr w14:val="tx1">
                                                    <w14:lumMod w14:val="50000"/>
                                                    <w14:lumOff w14:val="50000"/>
                                                </w14:schemeClr>
                                            </w14:solidFill>
                                        </w14:textFill>
                                    </w:rPr>
                                    <w:t>标签:</w:t>
                                </w:r>
                                <w:r
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值