diff --git a/Makefile b/Makefile index a63d201..1cd4b95 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ native: ## Build react-native project .PHONY: ios ios: native ## react-native ios sim - cd SheetJS; react-native run-ios; cd - + cd SheetJS; react-native run-ios --simulator="iPhone X"; cd - .PHONY: android android: native ## react-native android sim diff --git a/README.md b/README.md index b44b12f..0246682 100644 --- a/README.md +++ b/README.md @@ -77,8 +77,7 @@ Reproducing the full project is straightforward: react-native init SheetJS cd SheetJS npm i -S xlsx react react-native react-native-table-component react-native-fs -cp ../react-native.js index.ios.js -cp ../react-native.js index.android.js +cp ../react-native.js index.js react-native link ``` @@ -107,6 +106,9 @@ const wbout = XLSX.write(wb, {type:'binary', bookType:"xlsx"}); writeFile(file, wbout, 'ascii').then((r)=>{/* :) */}).catch((e)=>{/* :( */}); ``` +Note: for real app deployments, the `UIFileSharingEnabled` flag must be manually +set in the iOS project `Info.plist` file. + ## Other Demos #### Preact diff --git a/native.sh b/native.sh index b4f642a..cfa94cb 100755 --- a/native.sh +++ b/native.sh @@ -1,7 +1,7 @@ #!/bin/bash # xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */ if [ ! -e SheetJS ]; then - react-native init SheetJS + react-native init --version="0.53.3" SheetJS cd SheetJS npm i -S xlsx react-native-table-component react-native-fs cd - diff --git a/react-native.js b/react-native.js index dd9ec93..4d48eb6 100644 --- a/react-native.js +++ b/react-native.js @@ -2,8 +2,8 @@ import XLSX from 'xlsx'; import React, { Component } from 'react'; -import { AppRegistry, StyleSheet, Text, View, Button, Alert, Image } from 'react-native'; -import { Table, Row, Rows } from 'react-native-table-component'; +import { AppRegistry, StyleSheet, Text, View, Button, Alert, Image, ScrollView, TouchableWithoutFeedback } from 'react-native'; +import { Table, Row, Rows, TableWrapper } from 'react-native-table-component'; // react-native-fs import { writeFile, readFile, DocumentDirectoryPath } from 'react-native-fs'; @@ -21,12 +21,14 @@ const output = str => str.split("").map(x => x.charCodeAt(0)); */ const make_cols = refstr => Array.from({length: XLSX.utils.decode_range(refstr).e.c + 1}, (x,i) => XLSX.utils.encode_col(i)); +const make_width = refstr => Array.from({length: XLSX.utils.decode_range(refstr).e.c + 1}, () => 60); export default class SheetJS extends Component { constructor(props) { super(props); this.state = { data: [[1,2,3],[4,5,6]], + widthArr: [60, 60, 60], cols: make_cols("A1:C2") }; this.importFile = this.importFile.bind(this); @@ -46,7 +48,7 @@ export default class SheetJS extends Component { const data = XLSX.utils.sheet_to_json(ws, {header:1}); /* update state */ - this.setState({ data: data, cols: make_cols(ws['!ref']) }); + this.setState({ data: data, cols: make_cols(ws['!ref']), widthArr: make_width(ws['!ref']) }); }).catch((err) => { Alert.alert("importFile Error", "Error " + err.message); }); }} ]); @@ -67,7 +69,8 @@ export default class SheetJS extends Component { }).catch((err) => { Alert.alert("exportFile Error", "Error " + err.message); }); }; render() { return ( - + + SheetJS React Native Demo Import Data @@ -76,11 +79,22 @@ export default class SheetJS extends Component {