Bỏ qua, đến nội dung

Cài đặt và sử dụng — File Previewer Office

Tổng quan

Plugin plugin-file-previewer-office cho phép xem trước file Office (Word, Excel, PowerPoint) trực tiếp trong trình duyệt mà không cần tải về hay cài phần mềm Office. Plugin sử dụng dịch vụ Microsoft Office Online Viewer (view.officeapps.live.com) để render file.

Yêu cầu

Thành phầnYêu cầu
Server DigiforcePhiên bản >= 1.0
Plugin phụ thuộcplugin-file-manager (quản lý file đính kèm)
MạngFile phải truy cập được từ internet (Microsoft cần đọc file qua URL)

Điều kiện quan trọng

Plugin sử dụng Microsoft Office Online Viewer để render. Điều này yêu cầu:

  • File phải có URL public (truy cập được từ internet, không cần xác thực)
  • Server không nằm sau firewall chặn outbound (cần gọi đến view.officeapps.live.com)

Bước 1: Kích hoạt plugin

  1. Truy cập Settings → Plugin Manager
  2. Tìm plugin-file-previewer-office
  3. Bật công tắc Enable

Plugin chủ yếu hoạt động phía client — đăng ký thêm file type handler vào hệ thống preview. Server-side là plugin rỗng (không thêm API hay collection).

Bước 2: Sử dụng

Sau khi kích hoạt, khi user nhấn vào file Office trong trường attachment, hệ thống sẽ:

  1. Phát hiện loại file dựa trên MIME type hoặc extension
  2. Mở modal preview với iframe trỏ đến Microsoft Office Online Viewer
  3. Hiển thị nội dung file với các nút hành động

Hành động trong modal preview

NútMô tả
Open in new windowMở preview trong tab mới
DownloadTải file gốc về máy
CloseĐóng modal preview

Định dạng file được hỗ trợ

Theo MIME Type

MIME TypeLoại file
application/vnd.openxmlformats-officedocument.wordprocessingml.documentWord (.docx)
application/vnd.openxmlformats-officedocument.spreadsheetml.sheetExcel (.xlsx)
application/vnd.openxmlformats-officedocument.presentationml.presentationPowerPoint (.pptx)
application/mswordWord cũ (.doc)
application/vnd.ms-excelExcel cũ (.xls)
application/vnd.ms-powerpointPowerPoint cũ (.ppt)
application/vnd.oasis.opendocument.textOpenDocument Text (.odt)

Theo Extension

ExtensionLoại file
.docx, .docMicrosoft Word
.xlsx, .xlsMicrosoft Excel
.pptx, .pptMicrosoft PowerPoint
.odtOpenDocument Text

Cơ chế hoạt động chi tiết

Xây dựng Preview URL

Plugin tạo URL preview theo format:

https://view.officeapps.live.com/op/embed.aspx?src=<encoded-file-url>

Trong đó <encoded-file-url> là URL đầy đủ của file đã được encode.

Xác định URL file

Plugin xử lý URL file theo logic:

  1. Nếu URL bắt đầu bằng http:// hoặc https:// → sử dụng trực tiếp
  2. Nếu URL là đường dẫn tương đối → thêm location.origin phía trước

Phát hiện loại file

Plugin kiểm tra theo thứ tự:

  1. MIME type: Nếu file có mimetype thuộc danh sách Office MIME types → là file Office
  2. Extension: Lấy extension từ extname, name, filename hoặc url → kiểm tra trong danh sách Office extensions

Hai chế độ Preview

Khi user nhấn vào file attachment trong danh sách:

  • Mở modal kích thước 85% viewport (85vw × 85vh)
  • Iframe load Microsoft Office Online Viewer
  • Hỗ trợ chuyển đổi giữa nhiều file (navigation)

Inline Previewer

Khi file được hiển thị trong chế độ inline preview:

  • Render trực tiếp iframe trong container
  • Kích thước 100% × 100% của container cha
  • Không có modal wrapper

Cấu hình Storage cho Preview

Để preview hoạt động, file phải có URL truy cập được từ internet:

Storage TypePreview hoạt động?Ghi chú
S3 (public bucket)URL trực tiếp từ S3
Ali OSS (public)URL trực tiếp từ OSS
Tencent COS (public)URL trực tiếp từ COS
MinIO (public)URL từ MinIO với public access
Local storageChỉ nếu publicServer phải expose URL ra internet
Private storageKhôngMicrosoft không thể đọc file cần xác thực

Giải pháp cho storage private

Nếu dùng private storage, có thể:

  1. Tạo pre-signed URL (S3, OSS hỗ trợ) trước khi gửi cho viewer
  2. Hoặc sử dụng self-hosted viewer (LibreOffice Online, OnlyOffice) thay vì Microsoft

Lưu ý

  • Plugin không convert file trên server — chỉ redirect đến Microsoft Office Online Viewer
  • File .doc, .xls, .ppt (định dạng cũ) có thể hiển thị không hoàn hảo — khuyến nghị dùng .docx, .xlsx, .pptx
  • File lớn có thể tải chậm vì Microsoft cần download và render
  • Microsoft Office Online Viewer miễn phí nhưng có giới hạn kích thước file
  • Dữ liệu file được gửi qua Microsoft servers — cân nhắc bảo mật cho file nhạy cảm