日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術(shù)文章
文章詳情頁

VUE動態(tài)生成word的實現(xiàn)

瀏覽:168日期:2022-06-11 18:00:15

不廢話,直接上代碼。

前端代碼:

<template> <Form ref='formValidate' :model='formValidate' :rules='ruleValidate' :label-width='110'> <FormItem label='項目(全稱):' prop='orgName'> <Input v-model='formValidate.orgName' placeholder='請輸入項目名稱'></Input> </FormItem> <FormItem label='申請人:' prop='applyName' > <Input v-model='formValidate.applyName' placeholder='請輸入申請人'></Input> </FormItem> <FormItem label='電話:' prop='applyPhone'> <Input v-model='formValidate.applyPhone' placeholder='請輸入電話'></Input> </FormItem> <FormItem label='生效日期:' style='float: left'> <Row><FormItem prop='startDate'> <DatePicker type='date' format='yyyy-MM-dd' placeholder='請選擇生效日期' v-model='formValidate.startData'></DatePicker></FormItem> </Row> </FormItem> <FormItem label='失效日期:'> <Row><FormItem prop='endDate'> <DatePicker type='date' format='yyyy-MM-dd' placeholder='請選擇失效日期' v-model='formValidate.endData'></DatePicker></FormItem> </Row> </FormItem> <FormItem label='備注:' prop='vmemo'> <Input v-model='formValidate.vmemo' type='textarea' :autosize='{minRows: 2,maxRows: 5}' placeholder='備注'></Input> </FormItem> <FormItem> <Button type='primary' @click='handleSubmit(’formValidate’)'>生成申請單</Button> </FormItem> </Form></template><script> import axios from ’axios’; export default { data () { return {formValidate: { orgName: ’’, applyName: ’’, applyPhone: ’’, startDate: ’’, endDate: ’’, vmemo:’’},ruleValidate: { orgName: [ { required: true, message: ’項目名稱不能為空!’, trigger: ’blur’ } ], applyName: [ { required: true, message: ’申請人不能為空!’, trigger: ’blur’ } ], applyPhone: [ { required: true, message: ’電話不能為空!’, trigger: ’change’ } ], startDate: [ { required: true, type: ’date’, message: ’請輸入license有效期!’, trigger: ’change’ } ], endDate: [ { required: true, type: ’date’, message: ’請輸入license有效期!’, trigger: ’change’ } ],} } }, methods: { handleSubmit (name) {this.$refs[name].validate((valid) => { if (valid) { axios({ method: ’post’, url: this.$store.getters.requestNoteUrl, data: this.formValidate, responseType: ’blob’ }).then(res => { this.download(res.data); }); }}); }, download (data) {if (!data) { return}let url = window.URL.createObjectURL(new Blob([data]))let link = document.createElement(’a’);link.style.display = ’none’;link.href = url;link.setAttribute(’download’, this.formValidate.orgName+’(’+ this.formValidate.applyName +’)’+’-申請單.doc’);document.body.appendChild(link);link.click(); } } }</script>

后臺:

/** * 生成license申請單 */@RequestMapping(value = '/note', method = RequestMethod.POST)public void requestNote(@RequestBody LicenseRequestNoteModel noteModel, HttpServletRequest req, HttpServletResponse resp) { File file = null; InputStream fin = null; ServletOutputStream out = null; try { req.setCharacterEncoding('utf-8'); file = ExportDoc.createWord(noteModel, req, resp); fin = new FileInputStream(file); resp.setCharacterEncoding('utf-8'); resp.setContentType('application/octet-stream'); resp.addHeader('Content-Disposition', 'attachment;filename='+ noteModel.getOrgName()+'申請單.doc'); resp.flushBuffer(); out = resp.getOutputStream(); byte[] buffer = new byte[512]; // 緩沖區(qū) int bytesToRead = -1; // 通過循環(huán)將讀入的Word文件的內(nèi)容輸出到瀏覽器中 while ((bytesToRead = fin.read(buffer)) != -1) { out.write(buffer, 0, bytesToRead); } } catch (Exception e) { e.printStackTrace(); } finally { try { if (fin != null) fin.close(); if (out != null) out.close(); if (file != null) file.delete(); // 刪除臨時文件 } catch (IOException e) { e.printStackTrace(); } } }

public class ExportDoc { private static final Logger logger = LoggerFactory.getLogger(ExportDoc.class); // 針對下面這行有的報空指針,是目錄問題,我的目錄(項目/src/main/java,項目/src/main/resources),這塊也可以自己指定文件夾 private static final String templateFolder = ExportDoc.class.getClassLoader().getResource('/').getPath(); private static Configuration configuration = null; private static Map<String, Template> allTemplates = null; static { configuration = new Configuration(); configuration.setDefaultEncoding('utf-8'); allTemplates = new HashedMap(); try { configuration.setDirectoryForTemplateLoading(new File(templateFolder)); allTemplates.put('resume', configuration.getTemplate('licenseApply.ftl')); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } } public static File createWord(LicenseRequestNoteModel noteModel, HttpServletRequest req, HttpServletResponse resp) throws Exception { File file = null; req.setCharacterEncoding('utf-8'); // 調(diào)用工具類WordGenerator的createDoc方法生成Word文檔 file = createDoc(getData(noteModel), 'resume'); return file; } public static File createDoc(Map<?, ?> dataMap, String type) { String name = 'temp' + (int) (Math.random() * 100000) + '.doc'; File f = new File(name); Template t = allTemplates.get(type); try { // 這個地方不能使用FileWriter因為需要指定編碼類型否則生成的Word文檔會因為有無法識別的編碼而無法打開 Writer w = new OutputStreamWriter(new FileOutputStream(f), 'utf-8'); t.process(dataMap, w); w.close(); } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } return f; } private static Map<String, Object> getData(LicenseRequestNoteModel noteModel) throws Exception { Map<String, Object> map = new HashedMap(); map.put('orgName', noteModel.getOrgName()); map.put('applyName', noteModel.getApplyName()); map.put('applyPhone', noteModel.getApplyPhone()); map.put('ncVersion', noteModel.getNcVersionModel()); map.put('environment', noteModel.getEnvironmentModel()); map.put('applyType', noteModel.getApplyTypeModel()); map.put('mac', GetLicenseSource.getMacId()); map.put('ip', GetLicenseSource.getLocalIP()); map.put('startData', DateUtil.Date(noteModel.getStartData())); map.put('endData', DateUtil.Date(noteModel.getEndData())); map.put('hostName', noteModel.getHostNames()); map.put('vmemo', noteModel.getVmemo()); return map; } }

public class LicenseRequestNoteModel{ private String orgName = null; private String applyName = null; private String applyPhone = null; private String ncVersionModel= null; private String environmentModel= null; private String applyTypeModel= null; @JsonFormat(pattern = 'yyyy-MM-dd', timezone = 'GMT+8') @DateTimeFormat(pattern = 'yyyy-MM-dd') private Date startData= null; @JsonFormat(pattern = 'yyyy-MM-dd', timezone = 'GMT+8') @DateTimeFormat(pattern = 'yyyy-MM-dd') private Date endData= null; private String[] hostName= null; private String vmemo= null; private String applyMAC= null; private String applyIP= null; public String getOrgName() { return orgName; } public void setOrgName(String projectName) { this.orgName = projectName; } public String getApplyName() { return applyName; } public void setApplyName(String applyName) { this.applyName = applyName; } public String getApplyPhone() { return applyPhone; } public void setApplyPhone(String applyPhone) { this.applyPhone = applyPhone; } public String getNcVersionModel() { return ncVersionModel; } public void setNcVersionModel(String ncVersionModel) { this.ncVersionModel = ncVersionModel; } public String getEnvironmentModel() { return environmentModel; } public void setEnvironmentModel(String environmentModel) { this.environmentModel = environmentModel; } public String getApplyTypeModel() { return applyTypeModel; } public void setApplyTypeModel(String applyTypeModel) { this.applyTypeModel = applyTypeModel; } public Date getStartData() { return startData; } public void setStartData(Date startData) { this.startData = startData; } public Date getEndData() { return endData; } public void setEndData(Date endData) { this.endData = endData; } public String[] getHostName() { return hostName; } public String getHostNames() { return StringUtils.join(this.hostName,','); } public void setHostName(String[] hostName) { this.hostName = hostName; } public String getVmemo() { return vmemo; } public void setVmemo(String vmemo) { this.vmemo = vmemo; } public String getApplyMAC() { return applyMAC; } public void setApplyMAC(String applyMAC) { this.applyMAC = applyMAC; } public String getApplyIP() { return applyIP; } public void setApplyIP(String applyIP) { this.applyIP = applyIP; }}

補充知識:vue elementui 頁面預覽導入excel表格數(shù)據(jù)

html代碼:

<el-card class='box-card'><div slot='header' class='clearfix'><span>數(shù)據(jù)預覽</span></div><div class='text item'><el-table :data='tableData' border highlight-current-row style='width: 100%;'><el-table-column :label='tableTitle' ><el-table-column min- v-for=’item tableHeader’ :prop='item' :label='item' :key=’item’></el-table-column></el-table-column></el-table></div></el-card>

js代碼:

import XLSX from ’xlsx’ data() { return { tableData: ’’, tableHeader: ’’ }},mounted: { document.getElementsByClassName(’el-upload__input’)[0].setAttribute(’accept’, ’.xlsx, .xls’) document.getElementsByClassName(’el-upload__input’)[0].onchange = (e) => { const files = e.target.filesconst itemFile = files[0] // only use files[0]if (!itemFile) return this.readerData(itemFile) }},methods: { generateDate({ tableTitle, header, results }) { this.tableTitle = tableTitle this.tableData = results this.tableHeader = header }, handleDrop(e) { e.stopPropagation() e.preventDefault() const files = e.dataTransfer.files if (files.length !== 1) { this.$message.error(’Only support uploading one file!’) return } const itemFile = files[0] // only use files[0] this.readerData(itemFile) e.stopPropagation() e.preventDefault() }, handleDragover(e) { e.stopPropagation() e.preventDefault() e.dataTransfer.dropEffect = ’copy’ }, readerData(itemFile) { if (itemFile.name.split(’.’)[1] != ’xls’ && itemFile.name.split(’.’)[1] != ’xlsx’) { this.$message({message: ’上傳文件格式錯誤,請上傳xls、xlsx文件!’,type: ’warning’}); } else { const reader = new FileReader() reader.onload = e => {const data = e.target.resultconst fixedData = this.fixdata(data)const workbook = XLSX.read(btoa(fixedData), { type: ’base64’ })const firstSheetName = workbook.SheetNames[0] // 第一張表 sheet1const worksheet = workbook.Sheets[firstSheetName] // 讀取sheet1表中的數(shù)據(jù) delete worksheet[’!merges’]let A_l = worksheet[’!ref’].split(’:’)[1] //當excel存在標題行時worksheet[’!ref’] = `A2:${A_l}`const tableTitle = firstSheetNameconst header = this.get_header_row(worksheet)const results = XLSX.utils.sheet_to_json(worksheet)this.generateDate({ tableTitle, header, results }) }reader.readAsArrayBuffer(itemFile) } }, fixdata(data) { let o = ’’ let l = 0 const w = 10240 for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w))) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w))) return o }, get_header_row(sheet) { const headers = [] const range = XLSX.utils.decode_range(sheet[’!ref’]) let Cconst R = range.s.r /* start in the first row */ for (C = range.s.c; C <= range.e.c; ++C) { /* walk every column in the range */ var cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })] /* find the cell in the first row */ var hdr = ’UNKNOWN ’ + C // <-- replace with your desired defaultif (cell && cell.t) hdr = XLSX.utils.format_cell(cell) headers.push(hdr) } return headers }

以上這篇VUE動態(tài)生成word的實現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。

標簽: word
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
国产乱码精品一区二区亚洲| 中文字幕一区二区三区四区久久| 日韩精品三级| 一二三区精品| 国产欧美一区二区三区精品观看| 国产欧美三级| 你懂的亚洲视频| 麻豆网站免费在线观看| 欧美成人基地 | 国产一级一区二区| 国产综合婷婷| 中文字幕一区二区三区在线视频| 奇米狠狠一区二区三区| 精品国产欧美日韩| 999久久久免费精品国产| 最新日韩欧美| 青青国产精品| 日韩伦理在线一区| 亚洲深夜影院| 清纯唯美亚洲综合一区| 久久婷婷国产| 亚洲激情欧美| 国产情侣久久| 五月婷婷亚洲| 日韩精品免费视频一区二区三区 | 欧美亚洲精品在线| 国产精品毛片在线| 97久久中文字幕| 日韩不卡免费高清视频| 在线精品福利| 日韩欧美精品一区| 亚洲精品乱码久久久久久蜜桃麻豆 | 亚洲少妇诱惑| 日本v片在线高清不卡在线观看| 麻豆高清免费国产一区| 在线综合亚洲| 精品久久久中文字幕| 亚洲欧美日韩高清在线| 国产精品久久久久av蜜臀| 99久久99视频只有精品| 日韩毛片网站| 日本国产精品| 日韩高清在线观看一区二区| 国产在线看片免费视频在线观看| 蜜臀精品久久久久久蜜臀| 成人影视亚洲图片在线| 日韩欧乱色一区二区三区在线| 毛片在线网站| 青青国产91久久久久久| 亚洲国产一区二区三区在线播放| 欧美日韩亚洲三区| 国产高清一区| 国产专区精品| 欧美综合社区国产| 久久亚洲风情| 日韩欧美一区二区三区在线观看 | 亚洲狼人精品一区二区三区| 国产在线观看www| 欧美日韩亚洲一区二区三区在线| 欧美福利专区| 久久精品理论片| 日韩一区二区三区精品| 天堂日韩电影| 精品国产乱码久久久久久1区2匹| 中文字幕成人| 91高清一区| 久久麻豆视频| 亚洲精品观看| 黄色成人精品网站| 国产高潮在线| 久久99免费视频| 日韩精品亚洲专区| 午夜在线一区二区| 免费精品国产的网站免费观看| 精品三区视频| 国产精品亚洲四区在线观看| 蘑菇福利视频一区播放| 久久久久久美女精品| а√在线中文在线新版| 国产福利资源一区| 欧美日本久久| 国产日韩一区| 日本一区免费网站| 日韩午夜电影| 中文在线一区| 亚洲在线观看| 亚洲综合精品| 快she精品国产999| 丝袜国产日韩另类美女| 日韩午夜高潮| 另类av一区二区| 免费看黄色91| 在线观看视频免费一区二区三区| 国产精品社区| 蜜臀久久99精品久久久久久9| 日韩在线播放一区二区| 蘑菇福利视频一区播放| 在线亚洲精品| 午夜在线精品偷拍| 亚洲性视频在线| 日韩精品中文字幕一区二区| 欧美视频二区| 欧美激情精品| 不卡专区在线| 999国产精品视频| 午夜国产精品视频免费体验区| 蜜桃国内精品久久久久软件9| 欧美精选一区二区三区| 国产亚洲在线| 亚洲影院天堂中文av色| 青青青国产精品| 精品美女视频| 视频二区不卡| 91久久视频| 日韩精品欧美大片| 国产一区三区在线播放| 中文字幕色婷婷在线视频| 亚洲大片在线| 亚洲人妖在线| 精品国产精品国产偷麻豆 | 亚洲精选91| 国产乱论精品| 日韩欧美午夜| 蜜桃av一区二区| 国产日韩欧美三级| 国产盗摄——sm在线视频| 91久久久精品国产| 日韩一区二区三免费高清在线观看 | 四虎在线精品| 麻豆精品久久久| 国产精品99一区二区| 日韩精品免费视频人成| 福利在线一区| 亚洲精品在线二区| 国产精品99一区二区三| 久久高清精品| 日韩精品电影一区亚洲| 国精品产品一区| 久久亚洲影院| 精品日韩一区| 亚洲一区二区三区高清| 国产精品大片| 国产一区视频在线观看免费| 日本aⅴ亚洲精品中文乱码| 日韩一区二区在线免费| 婷婷综合成人| 一本大道色婷婷在线| 日本亚洲最大的色成网站www | 日本一区免费网站| 捆绑调教日本一区二区三区| 香蕉久久国产| 日韩av免费大片| 亚洲人成网77777色在线播放 | 精品国产中文字幕第一页| 国产精品呻吟| 国产精品国产三级国产在线观看| 日韩在线一二三区| 中文字幕在线视频久| 日韩av不卡一区二区| 免费视频亚洲| 国产成年精品| 国产毛片一区二区三区| 国精品一区二区三区| 欧美国产先锋| 亚洲精品免费观看| 欧美另类综合| 精品国产aⅴ| 日本一区二区三区视频在线看| 久久国产电影| 黄色aa久久| 欧美xxxx性| 日本成人中文字幕在线视频| 亚洲色诱最新| 亚洲国产专区| 中文字幕高清在线播放| 国产极品久久久久久久久波多结野| 三级欧美在线一区| 亚洲成人精品| 日韩av自拍| 精品一区二区三区视频在线播放| 日韩精品乱码av一区二区| 久久xxxx| 激情丁香综合| 亚洲成人一区在线观看| 精品一区二区三区中文字幕| 日本va欧美va欧美va精品| 蜜臀久久99精品久久久久宅男| 欧美日韩在线观看视频小说| 国产中文在线播放| 国产一区二区三区视频在线| 国产亚洲观看| 青青草国产精品亚洲专区无| 影音国产精品| 午夜日韩在线| 在线亚洲欧美| 国产亚洲毛片| 美女被久久久| 蜜桃一区二区三区在线| 亚洲在线免费| 免费久久99精品国产|