国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue導(dǎo)出word文檔(圖文示例)

這篇具有很好參考價值的文章主要介紹了vue導(dǎo)出word文檔(圖文示例)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

vue導(dǎo)出word文檔(圖文示例),# vue2實戰(zhàn)指南,vue.js,word,前端,vue導(dǎo)出word

第076個

查看專欄目錄: VUE

示例說明

在Vue中導(dǎo)出Word文檔,可以使用第三方庫file-saver和html-docx-js。首先需要安裝這兩個庫:

npm install file-saver html-docx-js --save

然后在Vue組件中使用這兩個庫來導(dǎo)出Word文檔:

示例效果圖

vue導(dǎo)出word文檔(圖文示例),# vue2實戰(zhàn)指南,vue.js,word,前端,vue導(dǎo)出word

導(dǎo)出的文件效果截圖

vue導(dǎo)出word文檔(圖文示例),# vue2實戰(zhàn)指南,vue.js,word,前端,vue導(dǎo)出word

示例源代碼

/*
* @Author: 大劍師蘭特(xiaozhuanlan),還是大劍師蘭特(CSDN)
* @此源代碼版權(quán)歸大劍師蘭特所有,可供學(xué)習(xí)或商業(yè)項目中借鑒,未經(jīng)授權(quán),不得重復(fù)地發(fā)表到博客、論壇,問答,git等公共空間或網(wǎng)站中。
* @Email: 2909222303@qq.com
* @weixin: gis-dajianshi
* @First published in CSDN
* @First published time: 2024-02-16
*/

<template>
	<div class="djs-box">
		<div class="topBox">
			<h3>vue導(dǎo)出word文檔</h3>
			<div>大劍師蘭特, 還是大劍師蘭特,gis-dajianshi</div>
			<h4>
				<el-button type="primary" size="mini" @click="exportToWord()"> 導(dǎo)出word文檔</el-button>
			</h4>
		</div>
		
		<div class="dajianshi" id="dajianshi">
			<h3> 這是我要導(dǎo)出的文件標題</h3>
			<p>This is a very small library that is capable of converting HTML documents to DOCX format that is used by
				Microsoft Word 2007 and onward. It manages to perform the conversion in the browser by using a feature
				called 'altchunks'. In a nutshell, it allows embedding content in a different markup language. We are
				using MHT document to ship the embedded content to Word as it allows to handle images. After Word opens
				such file, it converts the external content to Word Processing ML (this is how the markup language of
				DOCX files is called) and replaces the reference.</p>
			<p>
				Altchunks were not supported by Microsoft Word for Mac 2008 and are not supported by LibreOffice and
				Google Docs.</p>
			
		</div>
	</div>
</template>

<script>
	import FileSaver from 'file-saver';
	import htmlDocx from 'html-docx-js/dist/html-docx';
	export default {
		data() {
			return {
				message: 'hello world',
				price: 1234.56,
				date: '2022-01-01'
			}

		},
		methods: {
			exportToWord() {
				// 獲取要導(dǎo)出的HTML內(nèi)容
				const content = document.getElementById('dajianshi').innerHTML;
				// 將HTML內(nèi)容轉(zhuǎn)換為Word文檔
				const converted = htmlDocx.asBlob(content);
				// 使用FileSaver保存Word文檔
				FileSaver.saveAs(converted, 'example.docx');
			},
		},

	}
</script>
<style scoped>
	.djs-box {
		width: 1000px;
		height: 650px;
		margin: 50px auto;
		border: 1px solid deepskyblue;
	}

	.topBox {
		margin: 0 auto 0px;
		padding: 10px 0 20px;
		background: deepskyblue;
		color: #fff;
	}

	.dajianshi {
		width: 93%;
		height: 400px;
		margin: 5px auto 0;
		border: 1px solid #369;
		background-color: cde;
		padding: 20px;
	}

	p {
		font-size: 16px;
		text-align: left;
	}
</style>

參數(shù)說明:

要生成 DOCX,只需將 HTML 文檔(作為字符串)傳遞給 asBlob 方法以接收包含輸出文件的 Blob(或緩沖區(qū))。

var converted = htmlDocx.asBlob(content);
saveAs(converted, ‘test.docx’);

asBlob 可以采用其他選項來控制文檔的頁面設(shè)置

orientation: landscape or portrait (default)
margins: map of margin sizes (expressed in twentieths of point, see WordprocessingML documentation for details):
top: number (default: 1440, i.e. 2.54 cm)
right: number (default: 1440)
bottom: number (default: 1440)
left: number (default: 1440)
header: number (default: 720)
footer: number (default: 720)
gutter: number (default: 0)

重要提示:

please pass a complete, valid HTML (including DOCTYPE, html and body tags). This may be less convenient, but gives you possibility of including CSS rules in style tags.

html-docx-js is distributed as ‘standalone’ Browserify module (UMD). You can require it as html-docx. If no module loader is available, it will register itself as window.htmlDocx. See test/sample.html for details.

API 參考網(wǎng)址

https://www.npmjs.com/package/html-docx-js文章來源地址http://www.zghlxwxcb.cn/news/detail-826830.html

到了這里,關(guān)于vue導(dǎo)出word文檔(圖文示例)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • vue2 若依項目,使用plotly.js-dist圖表庫,將數(shù)據(jù)圖表一鍵導(dǎo)出為圖片

    vue2 若依項目,使用plotly.js-dist圖表庫,將數(shù)據(jù)圖表一鍵導(dǎo)出為圖片

    此代碼適用的場景是一個頁面有多個數(shù)據(jù)圖表。 首先需要拿到你生成數(shù)據(jù)圖表的數(shù)據(jù), 然后賦值給一個數(shù)組,數(shù)組需要在data定義,還需要去重。 ?然后點擊導(dǎo)出按鈕的代碼如下: 單個下載可以點擊數(shù)據(jù)圖表的照相機,可以實現(xiàn)單個下載。 如果數(shù)據(jù)圖表做了分頁和懶加載,無

    2024年02月12日
    瀏覽(25)
  • java 導(dǎo)出word,java根據(jù)提供word模板導(dǎo)出word文檔

    java 導(dǎo)出word,java根據(jù)提供word模板導(dǎo)出word文檔

    本文主要講解,利用poi-tl在word中動態(tài)生成表格行,進行文字、圖片填充。一共提供了兩種方式,1.基于本地文件 2.基于網(wǎng)絡(luò)文件 本文講解思路,1.先看示例,2. 示例對應(yīng)的代碼展示 3. 基本概念講解(api自行查閱文檔)。 這樣便于快速展示,不符合你的業(yè)務(wù)需求的可以直接劃走

    2024年02月14日
    瀏覽(23)
  • java利用模板導(dǎo)出word文檔

    java利用模板導(dǎo)出word文檔

    1.依賴: 1.普通數(shù)據(jù) 2.表格 3.1編輯模板:選中區(qū)域,按ctrl+F9,右鍵編輯域,選擇郵件合并,輸入?yún)?shù) 參數(shù)后面加“!”可以避免參數(shù)為null而報錯, ?3.2.代碼:? 3.3展示 1.數(shù)據(jù)類型 布爾型:等價于java的Boolean類型,不同的是不能直接輸出,可轉(zhuǎn)化為字符串輸出 日期型:等價于

    2024年02月04日
    瀏覽(26)
  • 【飛書】飛書導(dǎo)出md文檔 | 飛書markdown文檔導(dǎo)出 | 解決飛書只能導(dǎo)出pdf word

    【飛書】飛書導(dǎo)出md文檔 | 飛書markdown文檔導(dǎo)出 | 解決飛書只能導(dǎo)出pdf word

    github地址:https://github.com/Wsine/feishu2md 這是一個下載飛書文檔為 Markdown 文件的工具,使用 Go 語言實現(xiàn)。 請看這里:招募有需求和有興趣的開發(fā)者,共同探討開發(fā)維護,有興趣請聯(lián)系。 《一日一技 | 我開發(fā)的這款小工具,輕松助你將飛書文檔轉(zhuǎn)為 Markdown》 配置文件需要填寫

    2024年02月15日
    瀏覽(22)
  • 【Vue2+3入門到實戰(zhàn)】(17)VUE之VueCli腳手架自定認創(chuàng)建項目、ESlint代碼規(guī)范與修復(fù)、 ESlint自動修正插件的使用 詳細示例

    【Vue2+3入門到實戰(zhàn)】(17)VUE之VueCli腳手架自定認創(chuàng)建項目、ESlint代碼規(guī)范與修復(fù)、 ESlint自動修正插件的使用 詳細示例

    VueCli腳手架自定認創(chuàng)建項目 ESlint代碼規(guī)范與修復(fù) ESlint自動修正插件 1.安裝腳手架 (已安裝) 2.創(chuàng)建項目 選項 手動選擇功能 選擇vue的版本 是否使用history模式 選擇css預(yù)處理 選擇eslint的風(fēng)格 (eslint 代碼規(guī)范的檢驗工具,檢驗代碼是否符合規(guī)范) 比如:const age = 18; = 報錯!多加

    2024年02月03日
    瀏覽(127)
  • Java文件:XWPFDocument導(dǎo)出Word文檔

    Java文件:XWPFDocument導(dǎo)出Word文檔

    在Java項目開發(fā)過程中經(jīng)常會遇到導(dǎo)出Word文檔的業(yè)務(wù)場景。XWPFDocument是apache基金會提供的用戶導(dǎo)出Word文檔的工具類。 XWPFDocument:代表一個docx文檔 XWPFParagraph:代表文檔、表格、標題等各種的段落,由多個XWPFRun組成 XWPFRun:代表具有同樣風(fēng)格的一段文本 XWPFTable:代表一個表格

    2024年01月18日
    瀏覽(29)
  • 【PHPWrod】使用PHPWord導(dǎo)出word文檔

    目的:PHP通過PHPWord類庫導(dǎo)出文件為word。 開發(fā)語言及類庫:ThinkPHP、PHPWord 項目根目錄使用composer安裝PHPWord,安裝完成后會在vendor目錄下生成phpoffice文件夾,就是PHPWord類庫 前端代碼 PHP代碼 1、前端:先使用按鈕事件,在點擊事件里去請求后端返回的word文件的地址(這個地址是

    2024年02月09日
    瀏覽(23)
  • Java 實現(xiàn)導(dǎo)出 Word 文檔的方法詳解

    Java 實現(xiàn)導(dǎo)出 Word 文檔的方法詳解

    前些天發(fā)現(xiàn)了一個巨牛的人工智能學(xué)習(xí)網(wǎng)站,通俗易懂,風(fēng)趣幽默,忍不住分享一下給大家。點擊跳轉(zhuǎn)到網(wǎng)站,這篇文章男女通用,看懂了就去分享給你的碼吧。 在 Java 應(yīng)用程序中,有時候我們需要將數(shù)據(jù)導(dǎo)出為 Word 文檔,以便進行文檔的編輯、打印或共享。本文將介紹如何

    2024年02月15日
    瀏覽(19)
  • SpringBoot導(dǎo)出Word文檔的三種方式

    SpringBoot導(dǎo)出Word文檔的三種方式

    1、直接在Java代碼里創(chuàng)建Word文檔,設(shè)置格式樣式等,然后導(dǎo)出。(略) 需要的見:https://blog.csdn.net/qq_42682745/article/details/120867432 2、富文本轉(zhuǎn)換后的HTML下載為Word文檔。相當于把HTML轉(zhuǎn)為Word導(dǎo)出 3、使用模板技術(shù)導(dǎo)出。固定格式、可以寫入不同數(shù)據(jù) 其他: springboot版本:2.7.11 導(dǎo)

    2024年02月02日
    瀏覽(21)
  • postman 文檔、導(dǎo)出json腳本 導(dǎo)出響應(yīng)數(shù)據(jù) response ,showdoc導(dǎo)入postman json腳本 導(dǎo)出為文檔word或markdown

    postman 文檔、導(dǎo)出json腳本 導(dǎo)出響應(yīng)數(shù)據(jù) response ,showdoc導(dǎo)入postman json腳本 導(dǎo)出為文檔word或markdown

    保存、補全盡可能多的數(shù)據(jù)、描述 保存響應(yīng)數(shù)據(jù) Response :(如果導(dǎo)出接口數(shù)據(jù),會同步導(dǎo)出響應(yīng)數(shù)據(jù)) 請求接口后,點擊下方 Save as Example ?可以保存響應(yīng)數(shù)據(jù)到本地(會在左側(cè)接口下新增一個e.g. 文件用來保存響應(yīng)數(shù)據(jù)) 完善文檔相關(guān)信息 :接口名、參數(shù)描述、自定義文

    2024年02月11日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包