This commit is contained in:
SheetJS 2023-07-02 15:36:15 -04:00
parent e2b66a7d76
commit 50d991e967
4 changed files with 65 additions and 1 deletions

@ -1,3 +1,38 @@
# SheetJS + React Native Demo
Complete Reproduction of <https://docs.sheetjs.com/docs/demos/mobile/reactnative#demo>
Complete Reproduction of <https://docs.sheetjs.com/docs/demos/mobile/reactnative#demo>
This branch (`RNBU`) demonstrates `react-native-blob-util`.
## Installation
1) Install dependencies:
```bash
npm i
```
### iOS
2) (iOS only) link iOS project
```bash
cd ios; pod install; cd ..
```
3) run the development process:
```bash
npx react-native run-ios
```
### Android
4) ensure Java 11 is the current version
5) run the development process:
```bash
npx react-native run-android
```

@ -4,6 +4,28 @@ import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, Button, Alert, Image, ScrollView } from 'react-native';
import { Table, Row, Rows, TableWrapper } from 'react-native-table-component';
import { read, write } from 'xlsx';
import { pickSingle } from 'react-native-document-picker';
import { Platform } from 'react-native';
import RNFetchBlob from 'react-native-blob-util';
async function pickAndParse() {
/* rn-fetch-blob / react-native-blob-util need a copy */
const f = await pickSingle({allowMultiSelection: false, copyTo: "documentDirectory", mode: "open" });
let path = f.fileCopyUri;
if (Platform.OS === 'ios') path = path.replace(/^.*\/Documents\//, RNFetchBlob.fs.dirs.DocumentDir + "/");
const res = await (await fetch(path)).arrayBuffer(); // RN >= 0.72
// const res = await RNFetchBlob.fs.readFile(path, 'ascii'); // RN < 0.72
return read(new Uint8Array(res), {type: 'buffer'});
}
async function writeWorkbook(wb) {
const wbout = write(wb, {type:'buffer', bookType:"xlsx"});
const file = RNFetchBlob.fs.dirs.DocumentDir + "/sheetjsw.xlsx";
await RNFetchBlob.fs.writeFile(file, Array.from(wbout), 'ascii');
return file;
}
const make_width = ws => {
const aoa = utils.sheet_to_json(ws, {header:1}), res = [];
aoa.forEach((r) => { r.forEach((c, C) => { res[C] = Math.max(res[C]||60, String(c).length * 10); }); });

@ -374,6 +374,8 @@ PODS:
- React-jsinspector (0.72.1)
- React-logger (0.72.1):
- glog
- react-native-blob-util (0.17.1):
- React-Core
- react-native-document-picker (8.2.0):
- React-Core
- React-NativeModulesApple (0.72.1):
@ -537,6 +539,7 @@ DEPENDENCIES:
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- react-native-blob-util (from `../node_modules/react-native-blob-util`)
- react-native-document-picker (from `../node_modules/react-native-document-picker`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
@ -618,6 +621,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
React-logger:
:path: "../node_modules/react-native/ReactCommon/logger"
react-native-blob-util:
:path: "../node_modules/react-native-blob-util"
react-native-document-picker:
:path: "../node_modules/react-native-document-picker"
React-NativeModulesApple:
@ -691,6 +696,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: 184eae1ecdedc7a083194bd9ff809c93f08fd34c
React-jsinspector: d0b5bfd1085599265f4212034321e829bdf83cc0
React-logger: b8103c9b04e707b50cdd2b1aeb382483900cbb37
react-native-blob-util: 4949dcc0dd5ee25fcb5abe0687f67fa3d5cdf05a
react-native-document-picker: 495c444c0c773c6e83a5d91165890ecb1c0a399a
React-NativeModulesApple: 4f31a812364443cee6ef768d256c594ad3b20f53
React-perflogger: 3d501f34c8d4b10cb75f348e43591765788525ad

@ -12,6 +12,7 @@
"dependencies": {
"react": "18.2.0",
"react-native": "0.72.1",
"react-native-blob-util": "^0.17.1",
"react-native-document-picker": "^8.2.0",
"react-native-table-component": "^1.2.0",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz"