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

您的位置:首頁技術文章
文章詳情頁

VUE動態生成word的實現

瀏覽:173日期: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]; // 緩沖區 int bytesToRead = -1; // 通過循環將讀入的Word文件的內容輸出到瀏覽器中 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'); // 調用工具類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表格數據

html代碼:

<el-card class='box-card'><div slot='header' class='clearfix'><span>數據預覽</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表中的數據 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動態生成word的實現就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: word
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
免费视频久久| 亚洲欧美日韩视频二区| 欧美精品羞羞答答| 久久国产精品免费精品3p| 香蕉国产精品| 亚洲大片在线| 亚洲黄色免费看| 美女视频网站久久| 国产精品日本一区二区不卡视频 | 精品视频自拍| 国产欧美日韩一区二区三区四区| 中文字幕日韩欧美精品高清在线| 午夜日韩av| 欧美在线影院| 亚洲无线一线二线三线区别av| 久久免费黄色| 日韩毛片在线| 九色精品91| 国产国产精品| 99成人在线| 蜜桃一区二区三区在线观看| 蜜桃一区二区三区在线| 免费美女久久99| 亚洲精品观看| 欧美精品三级在线| 美日韩一区二区三区| 黄色网一区二区| 日韩欧美精品| 99pao成人国产永久免费视频| 国产视频一区欧美| 综合激情婷婷| 色8久久久久| 欧美日韩亚洲国产精品| 国产精品大片| 91欧美日韩| 欧美成人日韩| 亚洲精品九九| 国际精品欧美精品| 久久久久久久久久久9不雅视频| 激情婷婷久久| 中文字幕亚洲在线观看| 久久精品97| 美女福利一区二区三区| 五月婷婷六月综合| 日本不卡高清| 成人污污视频| 久久精选视频| 天堂av在线| 亚洲一区二区三区久久久| 欧美午夜网站| 99精品电影| 亚洲精品婷婷| 丰满少妇一区| 制服诱惑一区二区| 91午夜精品| 日韩成人高清| 亚洲精品自拍| 在线天堂资源www在线污| 欧美久久精品一级c片| 日本不卡视频在线| 中文字幕成在线观看| 国产色综合网| 美女久久精品| 亚洲欧美久久| 粉嫩av一区二区三区四区五区| 午夜久久一区| 久久尤物视频| 免费日韩视频| 国产高清不卡| 三级在线观看一区二区 | 91伊人久久| 99精品视频在线| 欧美aa一级| 88久久精品| 色婷婷狠狠五月综合天色拍| 日韩精品五月天| 波多野结衣一区| 久久av偷拍| 免费看黄色91| 亚洲精品在线影院| 国产精品亚洲片在线播放| 91欧美日韩在线| 美女精品在线观看| 国产美女高潮在线观看| 日本成人在线视频网站| 欧美va天堂| 色在线中文字幕| 国产精品一区二区三区av| 国产一区91| 麻豆理论在线观看| 国产激情综合| 日韩成人精品一区二区三区| 亚洲免费播放| 色爱综合av| 成人黄色av| 麻豆高清免费国产一区| 日韩欧美在线精品| 免费成人在线视频观看| 久久久久久黄| a天堂资源在线| 狠狠久久伊人| 久久只有精品| 国产精品密蕾丝视频下载| 亚洲精选91| 国产精品日本欧美一区二区三区| 狠狠久久婷婷| 激情欧美国产欧美| 欧美天堂视频| 国产欧洲在线| www.com.cn成人| 国产 日韩 欧美 综合 一区| 久久精品 人人爱| 日本免费一区二区视频| 亚洲精品在线二区| 自拍自偷一区二区三区| 免费中文字幕日韩欧美| 亚洲综合日本| 美国欧美日韩国产在线播放| 国产视频亚洲| 日韩va亚洲va欧美va久久| 日本久久一区| 六月婷婷综合| 亚洲一区二区三区久久久| 国产精品一区二区三区av麻 | 国产三级一区| 91亚洲无吗| 国产激情综合| 国产aⅴ精品一区二区四区| 久久精品国产在热久久| 久久精品免费看| 成人在线视频免费| www.51av欧美视频| 日韩国产欧美一区二区| 久久久精品午夜少妇| 欧美日韩国产探花| 男女男精品网站| 日韩av三区| 你懂的国产精品| 成人在线黄色| 激情五月综合网| 亚洲人亚洲人色久| 国产日韩欧美在线播放不卡| 精品国产美女a久久9999| 特黄毛片在线观看| 国产精品日本| 国产亚洲精品美女久久| 国产专区一区| 九九综合在线| 成人在线免费观看91| 午夜久久av| 91精品婷婷色在线观看| 婷婷综合国产| 日韩激情精品| 国产精品福利在线观看播放| 久久久夜夜夜| 日韩福利视频网| av在线最新| 中文字幕中文字幕精品| 国产精品美女在线观看直播| 神马午夜在线视频| 久久先锋影音| 国产精品激情电影| 欧美日韩国产观看视频| 尤物精品在线| 国产精区一区二区| 亚洲91精品| 91精品在线免费视频| 欧美日韩国产观看视频| 在线精品视频一区| 九九99久久精品在免费线bt| 国产综合精品| 国产精品一区二区三区av麻| 久久国产小视频| 国产香蕉精品| 精品91久久久久| 麻豆中文一区二区| 视频一区欧美日韩| 国产在线不卡一区二区三区| 亚洲欧美日韩精品一区二区| 精品欧美日韩精品| 视频国产精品| 国产精品99免费看| 国产精品调教视频| av不卡在线| 四虎国产精品免费观看| 亚洲乱码一区| 国产综合婷婷| 麻豆精品视频在线观看| 日本成人中文字幕在线视频| 韩国三级一区| 日韩精品视频中文字幕| 久久影院一区| 欧美激情91| 亚洲精品日本| 不卡在线一区二区| 日韩电影免费网址| 久久一区欧美| 国产日产精品_国产精品毛片| 亚洲国产日韩欧美在线| 国产aa精品|