From 1383cd6ed4ebffbdeb641c2060aa6e22fc2f6f9e Mon Sep 17 00:00:00 2001 From: SheetJS Date: Sun, 2 Jul 2023 20:23:05 -0400 Subject: [PATCH] step4 --- README.md | 36 +++++++++++++++++++++++++++++++++++- index.js | 19 +++++++++++++++++++ ios/Podfile.lock | 14 ++++++++++++-- package.json | 1 + 4 files changed, 67 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3fe1f7a..4c3f104 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,37 @@ # SheetJS + React Native Demo -Complete Reproduction of \ No newline at end of file +Complete Reproduction of + +This branch (`RNFA`) demonstrates `react-native-file-access`. + +## 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 +``` diff --git a/index.js b/index.js index 41a3fbc..c6cc107 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,25 @@ 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 { Dirs, FileSystem } from 'react-native-file-access'; + +async function pickAndParse() { + const f = await pickSingle({allowMultiSelection: false, copyTo: "documentDirectory", mode: "open" }); + let path = f.fileCopyUri; + const res = await (await fetch(path)).arrayBuffer(); + return read(new Uint8Array(res), {type: 'buffer'}); +} + +async function writeWorkbook(wb) { + const wbout = write(wb, {type:'base64', bookType:"xlsx"}); + const file = Dirs.DocumentDir + "/sheetjsw.xlsx"; + await FileSystem.writeFile(file, wbout, "base64"); + 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); }); }); diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 36ab9ee..4622582 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -374,8 +374,11 @@ PODS: - React-jsinspector (0.72.1) - React-logger (0.72.1): - glog - - react-native-document-picker (8.2.0): + - react-native-document-picker (8.2.1): - React-Core + - react-native-file-access (2.6.0): + - React-Core + - ZIPFoundation (= 0.9.11) - React-NativeModulesApple (0.72.1): - hermes-engine - React-callinvoker @@ -490,6 +493,7 @@ PODS: - Yoga (1.14.0) - YogaKit (1.18.1): - Yoga (~> 1.14) + - ZIPFoundation (0.9.11) DEPENDENCIES: - boost (from `../node_modules/react-native/third-party-podspecs/boost.podspec`) @@ -538,6 +542,7 @@ DEPENDENCIES: - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) - React-logger (from `../node_modules/react-native/ReactCommon/logger`) - react-native-document-picker (from `../node_modules/react-native-document-picker`) + - react-native-file-access (from `../node_modules/react-native-file-access`) - React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`) - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) - React-RCTActionSheet (from `../node_modules/react-native/Libraries/ActionSheetIOS`) @@ -573,6 +578,7 @@ SPEC REPOS: - OpenSSL-Universal - SocketRocket - YogaKit + - ZIPFoundation EXTERNAL SOURCES: boost: @@ -620,6 +626,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native/ReactCommon/logger" react-native-document-picker: :path: "../node_modules/react-native-document-picker" + react-native-file-access: + :path: "../node_modules/react-native-file-access" React-NativeModulesApple: :path: "../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios" React-perflogger: @@ -691,7 +699,8 @@ SPEC CHECKSUMS: React-jsiexecutor: 184eae1ecdedc7a083194bd9ff809c93f08fd34c React-jsinspector: d0b5bfd1085599265f4212034321e829bdf83cc0 React-logger: b8103c9b04e707b50cdd2b1aeb382483900cbb37 - react-native-document-picker: 495c444c0c773c6e83a5d91165890ecb1c0a399a + react-native-document-picker: 69ca2094d8780cfc1e7e613894d15290fdc54bba + react-native-file-access: a4398950e02999b5ab97f3055feb7ee28e6615a3 React-NativeModulesApple: 4f31a812364443cee6ef768d256c594ad3b20f53 React-perflogger: 3d501f34c8d4b10cb75f348e43591765788525ad React-RCTActionSheet: f5335572c979198c0c3daff67b07bd1ad8370c1d @@ -712,6 +721,7 @@ SPEC CHECKSUMS: SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 Yoga: 65286bb6a07edce5e4fe8c90774da977ae8fc009 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a + ZIPFoundation: b1f0de4eed33e74a676f76e12559ab6b75990197 PODFILE CHECKSUM: 2250de264ba5adbfd3fe13c5a448d934ea1d4b4d diff --git a/package.json b/package.json index 82bae7e..430e8d0 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "react": "18.2.0", "react-native": "0.72.1", "react-native-document-picker": "^8.2.0", + "react-native-file-access": "^2.6.0", "react-native-table-component": "^1.2.0", "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.0/xlsx-0.20.0.tgz" },