最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue實現(xiàn)導(dǎo)出word文檔的示例詳解

 更新時間:2024年02月18日 10:42:17   作者:還是大劍師蘭特  
這篇文章主要為大家詳細(xì)介紹了Vue如何使用第三方庫file-saver和html-docx-js實現(xiàn)導(dǎo)出word文檔的效果,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

示例說明

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

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

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

示例效果圖

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

示例源代碼

/*
* @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)出的文件標(biā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

到此這篇關(guān)于Vue實現(xiàn)導(dǎo)出word文檔的示例詳解的文章就介紹到這了,更多相關(guān)Vue導(dǎo)出word內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Vue?Hook?封裝通用型表格的詳細(xì)過程

    Vue?Hook?封裝通用型表格的詳細(xì)過程

    這篇文章主要介紹了Vue?Hook?封裝通用型表格,設(shè)計通用型表格組件首先,需要設(shè)計一個基礎(chǔ)的表格組件,它接受列配置、數(shù)據(jù)和分頁信息等參數(shù),本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2024-08-08
  • Vue+ElementUI?封裝簡易PaginationSelect組件的詳細(xì)步驟

    Vue+ElementUI?封裝簡易PaginationSelect組件的詳細(xì)步驟

    這篇文章主要介紹了Vue+ElementUI?封裝簡易PaginationSelect組件,這里簡單介紹封裝的一個Pagination-Select組件幾個步驟,結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-08-08
  • Vue中的異步組件函數(shù)實現(xiàn)代碼

    Vue中的異步組件函數(shù)實現(xiàn)代碼

    這篇文章主要介紹了Vue中的異步組件函數(shù)實現(xiàn)代碼,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-07-07
  • Vue.js按鍵修飾符及v-model修飾符示例詳解

    Vue.js按鍵修飾符及v-model修飾符示例詳解

    這篇文章主要介紹了Vue.js按鍵修飾符及v-model修飾符,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-05-05
  • 小白教程|一小時上手最流行的前端框架vue(推薦)

    小白教程|一小時上手最流行的前端框架vue(推薦)

    這篇文章主要介紹了前端框架vue,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • vue init webpack myproject構(gòu)建項目 ip不能訪問的解決方法

    vue init webpack myproject構(gòu)建項目 ip不能訪問的解決方法

    下面小編就為大家分享一篇vue init webpack myproject構(gòu)建項目 ip不能訪問的解決方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • el-select如何獲取當(dāng)前選中的對象所有(item)數(shù)據(jù)

    el-select如何獲取當(dāng)前選中的對象所有(item)數(shù)據(jù)

    在開發(fā)業(yè)務(wù)場景中我們通常遇到一些奇怪的需求,下面這篇文章主要給大家介紹了關(guān)于el-select如何獲取當(dāng)前選中的對象所有(item)數(shù)據(jù)的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • 關(guān)于vue3?解決getCurrentInstance?打包后線上環(huán)境報錯問題

    關(guān)于vue3?解決getCurrentInstance?打包后線上環(huán)境報錯問題

    這篇文章主要介紹了vue3?解決getCurrentInstance?打包后線上環(huán)境報錯問題,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-05-05
  • 基于Vue 服務(wù)端Cookies刪除的問題

    基于Vue 服務(wù)端Cookies刪除的問題

    今天小編就為大家分享一篇基于Vue 服務(wù)端Cookies刪除的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • vue中使用展示Markdown文檔說明

    vue中使用展示Markdown文檔說明

    文章介紹了如何在Vue項目中使用Markdown文檔,并展示了如何通過安裝和配置`markdown-it-vue`和`text-loader`來實現(xiàn)Markdown文檔的展示和下載
    2025-10-10

最新評論

陇南市| 宜宾市| 蓬溪县| 建昌县| 云和县| 沾益县| 平山县| 江门市| 玉山县| 南靖县| 河间市| 诸暨市| 临高县| 新乐市| 平塘县| 龙井市| 武山县| 穆棱市| 田东县| 黔南| 武川县| 惠水县| 大石桥市| 台中县| 鸡泽县| 仪征市| 定襄县| 高碑店市| 西畴县| 遵义县| 双峰县| 巨野县| 汕头市| 嫩江县| 时尚| 湟中县| 乐山市| 瑞金市| 镇巴县| 崇仁县| 延安市|