npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zhu-office-pptx

v1.0.0

Published

支持多种文件(**docx、excel、pdf、pptx**)预览的vue组件库,支持vue2/3。也支持非Vue框架的预览。

Readme

zhu-office

支持多种文件(docx、excel、pdf、pptx)预览的vue组件库,支持vue2/3。也支持非Vue框架的预览。

功能特色

  • 一站式:提供word(.docx)、pdf、excel(.xlsx, .xls)、ppt(.pptx)多种文档的在线预览方案,有它就够了
  • 简单:只需提供文档的src(网络地址)即可完成文档预览
  • 体验好:选择每个文档的最佳预览方案,保证用户体验和性能都达到最佳状态
  • 性能好:针对数据量较大做了优化

安装

#docx文档预览组件
npm install @zhu-office/docx [email protected]

#excel文档预览组件
npm install @zhu-office/excel [email protected]

#pdf文档预览组件
npm install @zhu-office/pdf [email protected]

#pptx文档预览组件
npm install @zhu-office/pptx [email protected]

如果是vue2.6版本或以下还需要额外安装 @vue/composition-api

npm install @vue/composition-api

使用示例

文档预览场景大致可以分为三种:

  • 有文档CDN地址,比如 https://***.docx,将文档地址字符串传给组件的src属性
  • 通过接口请求获取文件内容,此时可以获取文件的ArrayBuffer或Blob格式数据传给组件的src属性
  • 文件上传时预览,此时可以获取文件的ArrayBuffer或Blob格式数据传给组件的src属性

1. 使用网络地址预览

<template>
    <zhu-office-docx
        :src="docx"
        style="height: 100vh;"
        @rendered="rendered"
    />
</template>

<script>
//引入VueOfficeDocx组件
import VueOfficeDocx from '@zhu-office/docx'
//引入相关样式
import '@zhu-office/docx/lib/v3/index.css'

export default {
    components:{
        VueOfficeDocx
    },
    data(){
        return {
            docx: 'http://static.shanhuxueyuan.com/test6.docx' //设置文档网络地址,可以是相对地址
        }
    },
    methods:{
        rendered(){
            console.log("渲染完成")
        }
    }
}
</script>

2. 上传文件预览

读取文件的ArrayBuffer

<template>
    <div>
        <input type="file" @change="changeHandle"/>
        <zhu-office-docx :src="src"/>
    </div>
</template>

<script>
import VueOfficeDocx from '@zhu-office/docx'
import '@zhu-office/docx/lib/v3/index.css'

export default {
    components: {
        VueOfficeDocx
    },
    data(){
        return {
            src: ''
        }
    },
    methods:{
        changeHandle(event){
            let file = event.target.files[0]
            let fileReader = new FileReader()
            fileReader.readAsArrayBuffer(file)
            fileReader.onload =  () => {
                this.src = fileReader.result
            }
        }
    }
}
</script>

3. 二进制文件预览

如果后端给的不是CDN地址,而是一些POST接口,该接口返回二进制流,则可以调用接口获取文件的ArrayBuffer数据,传递给src属性。

<template>
    <zhu-office-docx
        :src="docx"
        style="height: 100vh;"
        @rendered="rendered"
    />
</template>

<script>
//引入VueOfficeDocx组件
import VueOfficeDocx from '@zhu-office/docx'
//引入相关样式
import '@zhu-office/docx/lib/v3/index.css'

export default {
    components:{
        VueOfficeDocx
    },
    data(){
        return {
            docx: ''
        }
    },
    mounted(){
        fetch('你的API文件地址', {
            method: 'post'
        }).then(res=>{
            //读取文件的arrayBuffer
            res.arrayBuffer().then(res=>{
                this.docx = res
            })
        })
    },
    methods:{
        rendered(){
            console.log("渲染完成")
        }
    }
}
</script>

通过网络地址预览示例如下,通过文件ArrayBuffer预览和上面docx的使用方式一致。

<template>
    <zhu-office-excel
        :src="excel"
        style="height: 100vh;"
        @rendered="renderedHandler"
        @error="errorHandler"
    />
</template>

<script>
//引入VueOfficeExcel组件
import VueOfficeExcel from '@zhu-office/excel'
//引入相关样式
import '@zhu-office/excel/lib/v3/index.css'

export default {
    components: {
        VueOfficeExcel
    },
    data() {
        return {
            excel: 'http://static.shanhuxueyuan.com/demo/excel.xlsx'//设置文档地址
        }
    },
    methods: {
        renderedHandler() {
            console.log("渲染完成")
        },
        errorHandler() {
            console.log("渲染失败")
        }
    }
}
</script>

通过网络地址预览示例如下,通过文件ArrayBuffer预览和上面docx的使用方式一致。

<template>
    <zhu-office-pdf
        :src="pdf"
        style="height: 100vh"
        @rendered="renderedHandler"
        @error="errorHandler"
    />
</template>

<script>
//引入VueOfficePdf组件
import VueOfficePdf from '@zhu-office/pdf'

export default {
    components: {
        VueOfficePdf
    },
    data() {
        return {
            pdf: 'http://static.shanhuxueyuan.com/test.pdf' //设置文档地址
        }
    },
    methods: {
        renderedHandler() {
            console.log("渲染完成")
        },
        errorHandler() {
            console.log("渲染失败")
        }
    }
}
</script>

通过网络地址预览示例如下,通过文件ArrayBuffer预览和上面docx的使用方式一致。

<template>
    <zhu-office-pptx
        :src="pdf"
        style="height: 100vh"
        @rendered="renderedHandler"
        @error="errorHandler"
    />
</template>

<script>
import VueOfficePptx from '@zhu-office/pptx'

export default {
    components: {
        VueOfficePptx
    },
    data() {
        return {
            pdf: 'http://****/test.pptx' //设置文档地址
        }
    },
    methods: {
        renderedHandler() {
            console.log("渲染完成")
        },
        errorHandler() {
            console.log("渲染失败")
        }
    }
}
</script>

项目依赖的第三方库

  • docx: 基于docx-preview库实现,相关issues暂不处理
  • pdf: 基于pdfjs库实现,实现了虚拟列表增加性能
  • excel: 基于exceljs 和 x-data-spreadsheet实现,全网样式支持更好
  • pptx: 基于自研库 pptx-preview 实现