Convert Figma logo to code with AI

501351981 logovue-office

支持word(.docx)、excel(.xlsx,.xls)、pdf、pptx等各类型office文件预览的vue组件集合,提供一站式office文件预览方案,支持vue2和3,也支持React等非Vue框架。Web-based pdf, excel, word, pptx preview library

4,158
479
4,158
130

Top Related Projects

35,258

📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs

Luckysheet is an online spreadsheet like excel that is powerful, simple to configure, and completely open source.

JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡

13,903

Excel Workbook Manager

13,037

The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.

6,725

Jspreadsheet is a lightweight vanilla javascript plugin to create amazing web-based interactive tables and spreadsheets compatible with other spreadsheet software.

Quick Overview

Vue-office is a Vue 3 component library for previewing and editing Microsoft Office documents (Word, Excel, PowerPoint) and PDF files directly in the browser. It provides a seamless integration of document viewing and editing capabilities within Vue applications.

Pros

  • Easy integration with Vue 3 applications
  • Supports multiple document formats (Word, Excel, PowerPoint, PDF)
  • Provides both viewing and editing functionalities
  • Responsive design for various screen sizes

Cons

  • Limited customization options for the document editor interface
  • Requires external dependencies for full functionality
  • May have performance issues with large or complex documents
  • Documentation could be more comprehensive

Code Examples

  1. Basic usage of the Word component:
<template>
  <vue-office-docx
    :src="docxUrl"
    @rendered="onRendered"
  />
</template>

<script setup>
import { VueOfficeDocx } from '@vue-office/docx'

const docxUrl = 'https://example.com/document.docx'
const onRendered = () => {
  console.log('Document rendered successfully')
}
</script>
  1. Using the Excel component with editing enabled:
<template>
  <vue-office-xlsx
    :src="xlsxUrl"
    :editable="true"
    @change="onChange"
  />
</template>

<script setup>
import { VueOfficeXlsx } from '@vue-office/xlsx'

const xlsxUrl = 'https://example.com/spreadsheet.xlsx'
const onChange = (data) => {
  console.log('Spreadsheet data changed:', data)
}
</script>
  1. Rendering a PDF file with custom options:
<template>
  <vue-office-pdf
    :src="pdfUrl"
    :options="pdfOptions"
  />
</template>

<script setup>
import { VueOfficePdf } from '@vue-office/pdf'

const pdfUrl = 'https://example.com/document.pdf'
const pdfOptions = {
  scale: 1.5,
  pageNumber: 1,
  rotation: 0
}
</script>

Getting Started

  1. Install the required packages:
npm install @vue-office/docx @vue-office/xlsx @vue-office/pdf
  1. Import and use the components in your Vue 3 application:
<template>
  <vue-office-docx :src="docxUrl" />
  <vue-office-xlsx :src="xlsxUrl" />
  <vue-office-pdf :src="pdfUrl" />
</template>

<script setup>
import { VueOfficeDocx } from '@vue-office/docx'
import { VueOfficeXlsx } from '@vue-office/xlsx'
import { VueOfficePdf } from '@vue-office/pdf'

const docxUrl = 'https://example.com/document.docx'
const xlsxUrl = 'https://example.com/spreadsheet.xlsx'
const pdfUrl = 'https://example.com/document.pdf'
</script>
  1. Make sure to include the necessary CSS files for proper styling:
<style>
@import '@vue-office/docx/lib/index.css';
@import '@vue-office/xlsx/lib/index.css';
@import '@vue-office/pdf/lib/index.css';
</style>

Competitor Comparisons

35,258

📗 SheetJS Spreadsheet Data Toolkit -- New home https://git.sheetjs.com/SheetJS/sheetjs

Pros of sheetjs

  • Broader support for various spreadsheet formats (XLS, XLSX, CSV, etc.)
  • More comprehensive feature set for complex spreadsheet operations
  • Larger community and more extensive documentation

Cons of sheetjs

  • Steeper learning curve due to its extensive API
  • Larger file size, which may impact load times in web applications

Code Comparison

sheetjs:

import * as XLSX from 'xlsx';

const workbook = XLSX.utils.book_new();
const worksheet = XLSX.utils.json_to_sheet(data);
XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");
XLSX.writeFile(workbook, "output.xlsx");

vue-office:

<template>
  <vue-office-excel
    :src="excelUrl"
    @rendered="onRendered"
    @error="onError"
  />
</template>

<script>
import { VueOfficeExcel } from '@vue-office/excel'

export default {
  components: { VueOfficeExcel },
  // ... rest of the component
}
</script>

Key Differences

  1. sheetjs focuses on spreadsheet manipulation, while vue-office is primarily for viewing Office documents in Vue applications.
  2. vue-office provides a more straightforward integration for Vue projects, with ready-to-use components.
  3. sheetjs offers more flexibility and control over spreadsheet data, making it suitable for complex data processing tasks.

Luckysheet is an online spreadsheet like excel that is powerful, simple to configure, and completely open source.

Pros of Luckysheet

  • More comprehensive spreadsheet functionality, including formulas, charts, and data validation
  • Supports collaborative editing and real-time updates
  • Offers a more Excel-like user interface and experience

Cons of Luckysheet

  • Larger file size and potentially higher resource usage
  • Steeper learning curve for implementation and customization
  • Limited support for other document types (e.g., Word, PowerPoint)

Code Comparison

Luckysheet initialization:

const options = {
    container: 'luckysheet',
    data: [{ name: "Sheet1", celldata: [{ r: 0, c: 0, v: "Hello" }] }]
};
luckysheet.create(options);

vue-office usage:

<template>
  <vue-office
    src="https://example.com/document.xlsx"
    :width="1000"
    :height="800"
  ></vue-office>
</template>

Summary

Luckysheet offers a more feature-rich spreadsheet experience with collaborative editing capabilities, making it suitable for complex spreadsheet applications. However, it may require more resources and development effort to implement.

vue-office provides a simpler solution for viewing various document types, including Excel files, with an easy-to-use Vue component. It's lighter and easier to integrate but offers limited editing capabilities compared to Luckysheet.

Choose Luckysheet for advanced spreadsheet functionality or vue-office for quick and easy document viewing across multiple formats.

JavaScript data grid with a spreadsheet look & feel. Works with React, Angular, and Vue. Supported by the Handsontable team ⚡

Pros of Handsontable

  • More comprehensive and feature-rich data grid solution
  • Supports multiple frameworks (React, Angular, Vue) and vanilla JavaScript
  • Extensive documentation and community support

Cons of Handsontable

  • Larger file size and potentially higher performance overhead
  • Steeper learning curve due to its extensive feature set
  • Commercial license required for some use cases

Code Comparison

Handsontable:

const hot = new Handsontable(container, {
  data: data,
  rowHeaders: true,
  colHeaders: true,
  filters: true,
  dropdownMenu: true
});

vue-office:

<template>
  <vue-office
    :src="fileUrl"
    :type="fileType"
    @rendered="onRendered"
    style="height: 100vh;"
  />
</template>

Key Differences

  • vue-office focuses specifically on Vue.js integration for office document viewing
  • Handsontable provides a more versatile data grid solution with editing capabilities
  • vue-office is lighter and easier to implement for basic document viewing needs
  • Handsontable offers more advanced data manipulation and analysis features

Use Cases

  • Choose vue-office for simple office document viewing in Vue.js applications
  • Opt for Handsontable when advanced data grid functionality is required across different frameworks

Community and Support

  • Handsontable has a larger community and more frequent updates
  • vue-office is more specialized but may have limited community resources
13,903

Excel Workbook Manager

Pros of exceljs

  • More comprehensive Excel manipulation capabilities, including reading, writing, and modifying Excel files
  • Broader compatibility with various Excel file formats (XLSX, CSV, etc.)
  • Larger community and more frequent updates

Cons of exceljs

  • Lacks built-in Vue.js integration, requiring additional setup for Vue projects
  • No direct support for in-browser Excel viewing or editing
  • Steeper learning curve for basic Excel operations

Code Comparison

exceljs:

const workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile('example.xlsx');
const worksheet = workbook.getWorksheet('Sheet1');
worksheet.getCell('A1').value = 'Hello, ExcelJS!';
await workbook.xlsx.writeFile('updated.xlsx');

vue-office:

<template>
  <vue-office-excel
    :src="excelUrl"
    @rendered="onRendered"
  />
</template>

<script>
export default {
  data() {
    return {
      excelUrl: 'path/to/excel/file.xlsx'
    }
  },
  methods: {
    onRendered() {
      console.log('Excel file rendered')
    }
  }
}
</script>

Summary

exceljs is a powerful library for server-side Excel manipulation, offering extensive features for reading, writing, and modifying Excel files. It supports various formats and has a large community. However, it lacks direct Vue.js integration and in-browser viewing capabilities.

vue-office, on the other hand, is specifically designed for Vue.js projects and provides easy-to-use components for in-browser Excel viewing. It has a simpler API but offers limited Excel manipulation capabilities compared to exceljs.

Choose exceljs for comprehensive Excel operations, especially in Node.js environments. Opt for vue-office when you need quick and easy Excel viewing in Vue.js applications with minimal setup.

13,037

The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.

Pros of ag-grid

  • More comprehensive and feature-rich data grid solution
  • Supports multiple frameworks (React, Angular, Vue) and vanilla JavaScript
  • Extensive documentation and community support

Cons of ag-grid

  • Steeper learning curve due to its complexity
  • Larger bundle size, which may impact performance for smaller projects
  • Commercial license required for some advanced features

Code Comparison

vue-office:

<template>
  <vue-office-excel :src="excelUrl" />
</template>

<script>
import { VueOfficeExcel } from '@vue-office/excel'

export default {
  components: { VueOfficeExcel },
  data() {
    return {
      excelUrl: 'path/to/excel/file.xlsx'
    }
  }
}
</script>

ag-grid:

<template>
  <ag-grid-vue
    class="ag-theme-alpine"
    :columnDefs="columnDefs"
    :rowData="rowData"
  />
</template>

<script>
import { AgGridVue } from 'ag-grid-vue3'

export default {
  components: { AgGridVue },
  data() {
    return {
      columnDefs: [/* column definitions */],
      rowData: [/* row data */]
    }
  }
}
</script>

Summary

While vue-office focuses on rendering Office documents in Vue applications, ag-grid is a more comprehensive data grid solution. ag-grid offers greater flexibility and features but comes with increased complexity and potential licensing costs. vue-office provides a simpler approach for displaying Office files, particularly Excel spreadsheets, within Vue applications.

6,725

Jspreadsheet is a lightweight vanilla javascript plugin to create amazing web-based interactive tables and spreadsheets compatible with other spreadsheet software.

Pros of jspreadsheet/ce

  • More comprehensive spreadsheet functionality, including formulas and advanced data manipulation
  • Larger community and more frequent updates, leading to better support and feature additions
  • Standalone JavaScript library, not tied to a specific framework like Vue.js

Cons of jspreadsheet/ce

  • Steeper learning curve due to more complex API and features
  • Potentially heavier and slower performance for simpler use cases
  • Less focus on other office document types (e.g., Word, PowerPoint)

Code Comparison

vue-office:

<template>
  <vue-office-excel :src="excelUrl" />
</template>

<script>
import { VueOfficeExcel } from '@vue-office/excel'

export default {
  components: { VueOfficeExcel },
  data() {
    return {
      excelUrl: 'path/to/excel/file.xlsx'
    }
  }
}
</script>

jspreadsheet/ce:

var spreadsheet = jspreadsheet(document.getElementById('spreadsheet'), {
    data: [
        ['Name', 'Age', 'City'],
        ['John', '30', 'New York'],
        ['Jane', '25', 'Los Angeles']
    ],
    columns: [
        { type: 'text', title: 'Name', width: 120 },
        { type: 'numeric', title: 'Age', width: 80 },
        { type: 'text', title: 'City', width: 120 }
    ]
});

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

vue-office

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

《演示效果》

《使用非Vue框架(原生js、React等)、或者Vue里面报错,看这里》

功能特色

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

安装

#docx文档预览组件
npm install @vue-office/docx vue-demi@0.14.6

#excel文档预览组件
npm install @vue-office/excel vue-demi@0.14.6

#pdf文档预览组件
npm install @vue-office/pdf vue-demi@0.14.6

#pptx文档预览组件
npm install @vue-office/pptx vue-demi@0.14.6

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

npm install @vue/composition-api

使用示例

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

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

1. 使用网络地址预览

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

<script>
//引入VueOfficeDocx组件
import VueOfficeDocx from '@vue-office/docx'
//引入相关样式
import '@vue-office/docx/lib/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"/>
        <vue-office-docx :src="src"/>
    </div>
</template>

<script>
import VueOfficeDocx from '@vue-office/docx'
import '@vue-office/docx/lib/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>
    <vue-office-docx
        :src="docx"
        style="height: 100vh;"
        @rendered="rendered"
    />
</template>

<script>
//引入VueOfficeDocx组件
import VueOfficeDocx from '@vue-office/docx'
//引入相关样式
import '@vue-office/docx/lib/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>
excel 文件预览示例

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

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

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

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

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

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

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

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

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

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

<script>
import VueOfficePptx from '@vue-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 实现,源码单独付费向作者索取

我要支持作者

如果该项目帮到了您,节省了您宝贵的开发时间,还请您不吝给项目点个免费的赞。

当然了,如果您能请作者喝杯咖啡,哪怕喝瓶娃娃哈矿泉水,也是对作者最真诚的鼓励,打赏用户欢迎添加微信,后续交流前端相关问题。

如果您有问题要咨询或者解决,可打赏咨询作者,自2024年12月起,可能不会及时处理issues内容,作者也要吃饭,也面临大龄程序员困境。

为什么没有开放源码(打赏50+送源码)

我们都知道,如果一件事情没有收益,那是很难长久的,特别是对于一个大龄程序员来说,花费大量的时间"用爱发电"对大家来说是非常值得尊敬的,而我感觉对家庭来说可能是不道德的,没有收益,没有正反馈,很难把这个库完善下去,我们也看到了,很多开源库已经多年没有更新了。为了后续开发出更好用的前端office文件预览库,本项目需要大家的支持!

源码需付费向作者索要(_打赏50+_),打赏用户(无论多少)均可添加作者微信,交流该库或者前端领域话题,源码不得用于开源(这也是关闭源码的原因之一,有些人直接复制开源作为自己项目)。

掘金小册

凝聚作者近10年工作经验的掘金小册《如何写出高质量的前端代码》 已经上线啦,欢迎前端同学关注,希望能够提升大家的前端编码水平。

小册已售 890+份,收到前端同学的高度评价,对提升日常开发效率和质量,有非常大的帮助。

NPM DownloadsLast 30 Days