--- title: CapacitorJS pagination_prev: demos/static/index pagination_next: demos/desktop/index sidebar_position: 5 sidebar_custom_props: summary: JS + Web View --- import current from '/version.js'; import CodeBlock from '@theme/CodeBlock'; The [NodeJS Module](/docs/getting-started/installation/nodejs) can be imported from the main entrypoint or any script in the project. The "Complete Example" creates an app that looks like the screenshots below:
iOS Android
![iOS screenshot](pathname:///cap/ios.png) ![Android screenshot](pathname:///cap/and.png)
:::warning Telemetry Before starting this demo, manually disable telemetry. On Linux and MacOS: ```bash npx @capacitor/cli telemetry off ``` To verify telemetry was disabled: ```bash npx @capacitor/cli telemetry ``` ::: ## Integration Details This example uses Svelte, but the same principles apply to other frameworks. #### Reading data The standard HTML5 File Input element logic works in CapacitorJS: ```html
{@html html}
``` #### Writing data `@capacitor/filesystem` can write Base64 strings: ```html
{@html html}
``` ## Demo :::note The Android demo was last tested on 2023 September 03 with CapacitorJS `5.3.0` and filesystem `5.1.3` on an emulated Pixel 3 + Android 13 ("Tiramisu") API 33. The iOS demo was last tested on 2023 September 03 with CapacitorJS `5.3.0` and filesystem `5.1.3` on an emulated iPhone SE (3rd generation) + iOS 16.4. ::: ### Base Project 0) Follow the official "Environment Setup"[^1] instructions to set up Android and iOS targets :::caution pass iOS development is only supported on macOS. :::
Installation Notes (click to show) CapacitorJS requires Java 17.
1) Disable telemetry. ```bash npx @capacitor/cli telemetry off ``` Verify that telemetry is disabled by running ```bash npx @capacitor/cli telemetry ``` (it should print `Telemetry is off`) 2) Create a new Svelte project: ```bash npm create vite@latest sheetjs-cap -- --template svelte cd sheetjs-cap ``` 3) Install dependencies: {`\ npm i --save https://cdn.sheetjs.com/xlsx-${current}/xlsx-${current}.tgz npm i --save @capacitor/core @capacitor/cli @capacitor/filesystem`} 4) Create CapacitorJS structure: ```bash npx cap init sheetjs-cap com.sheetjs.cap --web-dir=dist npm run build ``` 5) Download [`src/App.svelte`](pathname:///cap/App.svelte) and replace: ```bash curl -o src/App.svelte -L https://docs.sheetjs.com/cap/App.svelte ``` ### Android 6) Create Android app ```bash npm i --save @capacitor/android npx cap add android ``` 7) Enable file reading and writing in the Android app. The following lines must be added to `android/app/src/main/AndroidManifest.xml` after the `Permissions` comment: ```xml title="android/app/src/main/AndroidManifest.xml (add to file)" ``` 8) Run the app in the simulator ```bash npm run build npx cap sync npx cap run android ``` 9) Test the app Open the app and observe that presidents are listed in the table. Touch "Export XLSX" and the emulator will ask for permission: Tap "Allow" and a popup will be displayed with a path. To see the generated file, switch to the "Files" app in the simulator, tap the `≡` icon and tap "Documents". Tap "Documents" folder to find `SheetJSCap.xlsx`. ### iOS 10) Create iOS app ```bash npm i --save @capacitor/ios npx cap add ios ``` 11) Enable file sharing and make the documents folder visible in the iOS app. The following lines must be added to `ios/App/App/Info.plist`: ```xml title="ios/App/App/Info.plist (add to file)" UIFileSharingEnabled LSSupportsOpeningDocumentsInPlace CFBundleDevelopmentRegion ``` (The root element of the document is `plist` and it contains one `dict` child) 12) Run the app in the simulator ```bash npm run build npx cap sync npx cap run ios ``` 13) Test the app Open the app and observe that presidents are listed in the table. Touch "Export XLSX" and a popup will be displayed. To see the generated file, switch to the "Files" app in the simulator and look for `SheetJSCap.xlsx` in "On My iPhone" > "`sheetjs-cap`" [^1]: See ["Environment Setup"](https://capacitorjs.com/docs/getting-started/environment-setup) in the CapacitorJS documentation.