vue-office
支持word(.docx)、excel(.xlsx,.xls)、pdf、pptx等各类型office文件预览的vue组件集合,提供一站式office文件预览方案,支持vue2和3,也支持React等非Vue框架。Web-based pdf, excel, word, pptx preview library
Top Related Projects
📗 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 ⚡
Excel Workbook Manager
The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.
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
- 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>
- 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>
- 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
- Install the required packages:
npm install @vue-office/docx @vue-office/xlsx @vue-office/pdf
- 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>
- 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
📗 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
- sheetjs focuses on spreadsheet manipulation, while vue-office is primarily for viewing Office documents in Vue applications.
- vue-office provides a more straightforward integration for Vue projects, with ready-to-use components.
- 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
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.
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.
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 designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
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+份ï¼æ¶å°å端åå¦çé«åº¦è¯ä»·ï¼å¯¹æåæ¥å¸¸å¼åæçåè´¨éï¼æé常大ç帮å©ã
Top Related Projects
📗 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 ⚡
Excel Workbook Manager
The best JavaScript Data Table for building Enterprise Applications. Supports React / Angular / Vue / Plain JavaScript.
Jspreadsheet is a lightweight vanilla javascript plugin to create amazing web-based interactive tables and spreadsheets compatible with other spreadsheet software.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot