---
title: Ionic
pagination_prev: demos/static/index
pagination_next: demos/desktop/index
sidebar_position: 4
sidebar_custom_props:
summary: Native Components + Web View
---
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 |
![iOS screenshot](pathname:///ionic/ios.png)
|
:::warning Telemetry
Before starting this demo, manually disable telemetry. On Linux and MacOS:
```bash
rm -rf ~/.ionic/
mkdir ~/.ionic
cat < ~/.ionic/config.json
{
"version": "6.20.1",
"telemetry": false,
"npmClient": "npm"
}
EOF
npx @capacitor/cli telemetry off
```
To verify telemetry was disabled:
```bash
npx @ionic/cli config get -g telemetry
npx @capacitor/cli telemetry
```
:::
## Integration Details
:::caution
The latest version of Ionic uses CapacitorJS. These notes are for Cordova apps.
:::
### Angular
`Array>` neatly maps to a table with `ngFor`:
```html
{{val}}
```
### Cordova
`@ionic-native/file` reads and writes files on devices.
_Reading Files_
`readAsArrayBuffer` returns `ArrayBuffer` objects suitable for `array` type:
```ts
/* read a workbook */
const ab: ArrayBuffer = await this.file.readAsArrayBuffer(url, filename);
const wb: XLSX.WorkBook = XLSX.read(ab, {type: 'array'});
```
_Writing Files_
`array` type can be converted to blobs that can be exported with `writeFile`:
```ts
/* write a workbook */
const wbout: ArrayBuffer = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
let blob = new Blob([wbout], {type: 'application/octet-stream'});
this.file.writeFile(url, filename, blob, {replace: true});
```
## Demo
:::note
This demo was tested on an Intel Mac on 2023 March 19 with Cordova.
The file integration uses `@ionic-native/file` version `5.36.0`.
The iOS simulator runs iOS 16.5 on an iPhone SE (3rd Generation).
:::
0) Disable telemetry as noted in the warning.
Install required global dependencies:
```bash
npm i -g cordova-res @angular/cli native-run
```
Follow the [React Native demo](/docs/demos/mobile/reactnative) to ensure iOS and Android sims are ready.
1) Create a new project:
```bash
npx @ionic/cli start SheetJSIonic blank --type angular --cordova --quiet --no-git --no-link --confirm
```
If a prompt asks to confirm Cordova use, enter `Yes` to continue.
If a prompt asks about creating an Ionic account, enter `N` to opt out.
2) Set up Cordova:
```bash
cd SheetJSIonic
npx @ionic/cli cordova platform add ios --confirm
npx @ionic/cli cordova plugin add cordova-plugin-file
npm install --save @ionic-native/core @ionic-native/file @ionic/cordova-builders
```
:::caution
In some test runs, the `plugin add cordova-plugin-file` step reported an error:
```
CordovaError: Could not load API for ios project
```
This was resolved by removing and reinstalling the `ios` platform:
```bash
npx @ionic/cli cordova platform rm ios
npx @ionic/cli cordova platform add ios --confirm
```
:::
3) Install dependencies:
```bash
npm install --save https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz
```
4) Add `@ionic-native/file` to the module. Differences highlighted below:
```ts title="src/app/app.module.ts"
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
// highlight-next-line
import { File } from '@ionic-native/file/ngx';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
// highlight-next-line
providers: [File, { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }],
bootstrap: [AppComponent],
})
export class AppModule {}
```
5) Download [`home.page.ts`](pathname:///ionic/home.page.ts) and replace:
```bash
curl -o src/app/home/home.page.ts -L https://docs.sheetjs.com/ionic/home.page.ts
```
**iOS Testing**
```bash
npx @ionic/cli cordova emulate ios
```
:::caution
In some test runs, the `cordova build ios --emulator` step failed with error:
```
> cordova build ios --emulator
Could not load API for ios project
```
This was resolved by forcefully installing `cordova-ios`:
```bash
npm i --save cordova-ios
```
:::