FylarOpen/fylar-office-sdk
À propos
Fylar Office SDK packages, documentation, and examples for web applications.
Apprentissage et éducationProgression mesurée des étoiles
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
OriginalFylar Office SDK Examples and Documentation
Version: 1.2.0 | Last updated: 2026-11-11
English · 简体中文
When upgrading to 1.2.0, rename userData.nickName to userData.commonName.
Install from npm
npm install @fylar/office-sdk
The package targets modern browsers and includes its workers, WebAssembly
modules, locale assets, and styles. For Vite, register the Runtime deployment
plugin once in vite.config.js:
import { defineConfig } from "vite";
import officeSdk from "@fylar/office-sdk/vite";
export default defineConfig({
plugins: [officeSdk()]
});
Then use the default package export in application code:
import OfficeSdk from "@fylar/office-sdk";
const { widget } = await OfficeSdk.openfile({
fileName: "demo.docx",
file: fileBlob
});
const app = await widget.mount("#office-container").render();
The Vite integration serves the Runtime from /fylar-office-sdk/ during
development and copies it unchanged to dist/fylar-office-sdk/ during
production builds. Runtime, Worker, WebAssembly, locale, and vendor files are
not bundled into application code.
Optional Runtime preloading is available from the deployed directory:
const preloadUrl = new URL("/fylar-office-sdk/preload.js", window.location.origin).href;
void import(/* @vite-ignore */ preloadUrl);
For a different deployment path, pass the same runtimeBaseUrl to the Vite
plugin and SDK adapter:
// vite.config.js
officeSdk({ runtimeBaseUrl: "/assets/office-sdk/" });
// Application entry
OfficeSdk.configure({ runtimeBaseUrl: "/assets/office-sdk/" });
Directory Overview
| Directory | Description |
|---|---|
lib/ |
Office SDK runtime artifacts. Keep the directory structure unchanged when deploying. |
docs/HTML/ |
Static HTML documentation. It opens the Chinese documentation by default; the English documentation is available under docs/HTML/en-US/. |
docs/Markdown/ |
Bilingual Markdown source files for further editing or importing into an internal knowledge base. |
examples/full-evaluation/ |
Full evaluation page for locally testing file opening, document creation, API calls, and event subscriptions. |
examples/html/ |
Native HTML example that can be served directly from a static server. |
examples/vue/ |
Vue 3 + Vite example demonstrating component-based integration. |
examples/react/ |
React 18 + Vite example demonstrating component-based integration. |
shared/ |
Shared helpers for file validation, open options, and the widget lifecycle across examples. |
Documentation
The complete documentation is generated under docs/HTML/. It opens the Chinese documentation by default and lets you switch to English from within the documentation pages. Serve it over HTTP together with the examples:
http://127.0.0.1:8000/docs/HTML/
You can also open the English documentation directly:
http://127.0.0.1:8000/docs/HTML/en-US/
To view or synchronize the source documentation, use docs/Markdown/zh-CN/ and docs/Markdown/en-US/.
Start the HTML Examples
Start a static server from the SDK package root. Do not open the examples directly with file://:
python3 -m http.server 8000
Or:
npx http-server -p 8000
After the server starts, visit:
http://127.0.0.1:8000/examples/html/
The HTML example includes file type validation, entry points for creating DOCX/XLSX/PPTX files, language/read-only/toolbar options, error messages, and logic for disposing of the previous instance before reopening a file. It can be used as a reference for native JavaScript integration.
Open the full evaluation example at:
http://127.0.0.1:8000/examples/full-evaluation/
This page is a bundled static artifact suitable for evaluating document opening and creation, API calls, event subscriptions, and bilingual documentation access.
Start the Vue / React Examples
Vue example:
cd examples/vue
npm install
npm run dev
The default development URL is http://127.0.0.1:5173/. To preview the production build, run npm run build && npm run preview; the default preview URL is http://127.0.0.1:4173/.
React example:
cd examples/react
npm install
npm run dev
The default development URL is http://127.0.0.1:5174/. To preview the production build, run npm run build && npm run preview; the default preview URL is http://127.0.0.1:4174/.
Static Directory Integration
import OfficeSdk from "./lib/UI.js";
const { widget } = await OfficeSdk.openfile({
fileName: "demo.docx",
file: fileBlob
});
const app = await widget.mount("#office-container").render();
// Wait for the current instance to close before navigating away,
// unmounting the component, or reopening a file.
await widget.close();
UI.js automatically loads style.css from the same directory. To start downloading the styles earlier, you can additionally import "./lib/style.css" from your entry file.
To create a blank document, pass 1, 2, or 3 to create a DOCX, XLSX, or PPTX file, respectively:
const { widget } = await OfficeSdk.createfile(1, options);
const app = await widget.mount("#office-container").render();
You can also reuse the controller in shared/officeWidget.js to consistently handle instance disposal before reopening a file, viewport updates after the container is resized, and common error classification. See shared/README.md for details.
To begin opening a document immediately after the page loads, you can optionally preload the runtime:
import "./lib/preload.js";
preload.js only starts loading the SDK runtime, worker, and document application chunks early. Without it, UI.js still loads them on demand.
API
openfile API
Signature
openfile(...) creates an Office document widget that is ready to be mounted:
const result = await OfficeSdk.openfile(fileData, options);
| Parameter | Type | Description |
|---|---|---|
fileData |
OfficeWidgetFileData |
File information, including the file name and either file content or a file URL. |
options |
OfficeSdkOpenOptions |
Optional open configuration for the user, interface, and open mode. |
Complete Example
import OfficeSdk from "./lib/UI.js";
const { widget } = await OfficeSdk.openfile(
{
fileName: "demo.docx",
file
},
{
userData: {
userId: "u1",
commonName: "Alice"
},
uiOptions: {
showTopBar: true,
showBottomBar: true
},
mode: {
lang: "en-US",
readOnly: false
}
}
);
const app = await widget.mount("#office-container").render();
fileData Parameter
The first parameter of openfile(...) is a file information object:
type OfficeWidgetFileData = {
docId?: string;
fileName: string;
file: Blob | ArrayBuffer | ArrayBufferView | string | null | undefined;
};
| Field | Type | Description |
|---|---|---|
docId |
string |
Optional. Document ID used for caching, collaboration, and instance lifecycle identification. If omitted, the SDK generates a local ID from the file information. |
fileName |
string |
Required. Used to identify the document type; explicitly providing it is always recommended. |
file |
Blob | ArrayBuffer | ArrayBufferView | string | null | undefined |
Required. Supports binary file data, typed arrays, and URLs provided as strings. |
options Parameter
The second parameter of openfile(...) is an optional configuration object:
type OfficeSdkOpenOptions = {
userData?: OfficeSdkUser | null;
uiOptions?: OfficeSdkUiOptions;
mode?: OfficeSdkOpenMode;
};
| Field | Type | Description |
|---|---|---|
userData |
OfficeSdkUser | null |
Optional. Information about the current user. If omitted, the SDK supplies a default local user. |
uiOptions |
OfficeSdkUiOptions |
Optional. Controls the visibility of the top toolbar and bottom status bar. |
mode |
OfficeSdkOpenMode |
Optional. Controls read-only state and the document language. |
userData Parameter
type OfficeSdkUser = {
clientId?: string;
userId?: string;
commonName?: string;
avatar?: string;
opts?: Record<string, unknown>;
};
| Field | Type | Description |
|---|---|---|
clientId |
string |
Optional. Client identifier. |
userId |
string |
Optional. User ID. |
commonName |
string |
Optional. User display name. |
avatar |
string |
Optional. User avatar URL. |
opts |
Record<string, unknown> |
Optional. Custom fields for the integrating application. |
mode Parameter
mode specifies how the document is opened:
type OfficeSdkOpenMode = {
readOnly?: boolean;
lang?: "zh-CN" | "en-US" | (string & {});
};
| Field | Type | Description |
|---|---|---|
readOnly |
boolean |
Optional. When true, the SDK opens the document in read-only mode. The default is false. |
lang |
"zh-CN" | "en-US" | string |
Optional. Specifies the document language. If omitted, the SDK falls back to window.lang, <html lang>, and then the browser language. |
uiOptions Parameter
uiOptions controls the SDK's top toolbar and bottom status bar:
type OfficeSdkUiOptions = {
showTopBar?: boolean;
showBottomBar?: boolean;
};
| Field | Type | Description |
|---|---|---|
showTopBar |
boolean |
Optional. Whether to show the top toolbar. The default is true. |
showBottomBar |
boolean |
Optional. Whether to show the bottom status bar. The default is true. |
To provide only UI configuration, write:
const { widget } = await OfficeSdk.openfile(
{
fileName: "demo.xlsx",
file
},
{
uiOptions: {
showTopBar: true,
showBottomBar: false
}
}
);
Return Value
openfile(...) returns:
type OfficeWidgetOpenResult = {
docType: number;
widget: OfficeWidgetApp;
};
| Field | Type | Description |
|---|---|---|
docType |
number |
Numeric document type identifier. |
widget |
OfficeWidgetApp |
Mountable, renderable, and disposable widget instance. |
Widget Instance
widget provides the following members:
| Member | Type | Description |
|---|---|---|
mount(target) |
(target: string | HTMLElement) => OfficeWidgetApp |
Specifies the mount target. target can be a CSS selector string or an HTMLElement. |
render() |
() => Promise<OfficeSdkRenderedApp> |
Renders the document and returns the document application instance. |
close() |
() => Promise<void> |
Closes the current instance and releases runtime resources. |
docId |
string |
Current document ID. |
docType |
number |
Current document type. |
docTypeName |
string |
Current document type name. |
Instance Lifecycle
The recommended instance lifecycle is:
- Call
openfile(...)to create a widget that is ready to be mounted. - Call
widget.mount(...)to specify the container. - Call
widget.render()to render the document. - Call
widget.close()before navigating away, unmounting the component, or reopening a file.
Reopening a File
Close the previous instance before opening another file:
let currentWidget = null;
async function replaceFile(file) {
await currentWidget?.close();
const { widget } = await OfficeSdk.openfile({
fileName: file.name,
file
});
await widget.mount("#office-container").render();
currentWidget = widget;
}
Deployment Notes
- Serve the examples over HTTP/HTTPS. Opening them directly with
file://is not supported. - The default npm export is a bundler adapter. Its Runtime base URL defaults to
/fylar-office-sdk/. - With Vite, add
@fylar/office-sdk/viteto the Vite plugin list. It serves Runtime files during development and copies them to the production output directory. - With another bundler, deploy the files and directories listed by
runtimeFilesandruntimeDirectoriesinlib/manifest.json, then configure the matching URL throughOfficeSdk.configure({ runtimeBaseUrl }). - For direct static-directory integration, deploy the complete
lib/directory and importlib/UI.jsinstead of the npm package default entry. - Configure the server to return
.wasmfiles correctly. The recommended MIME type isapplication/wasm. lib/manifest.jsonlists Runtime files and directories, entry points, workers, WASM files, and internal chunks for deployment allowlist validation.lib/package.jsonrecords the static asset package name, version, entry points, type declarations, and stylesheet entry for delivery identification and tooling.- When deploying to a CDN, preserve all relative paths within
lib/.
Explorer des projets similaires
Chargement…