excel file is not being picked and not readable as well in expo reactnative

16 Views Asked by At
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Button } from 'react-native';
import * as DocumentPicker from 'expo-document-picker';
import { DocumentDirectoryPath } from 'react-native-fs'; // Import DocumentDirectoryPath from react-native-fs

export default function App() {
  const getDocs = async () => {
    try {
      const res = await DocumentPicker.getDocumentAsync({
        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
      });
       console.log(res.uri)


      if (res.type === 'success' && res.uri) {
        const filePath = res.uri; // Use the URI directly, no need to construct file path
        const fileContent = await readFile(filePath, 'base64');
        console.log('File content:', fileContent);
      }
    } catch (error) {
      console.error('Error while picking the file', error);
    }
return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
      <Button title='Go To Gallery' onPress={getDocs}/>
      <StatusBar style="auto" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

I used this code but the file URI is something like this:file:///data/user/0/host.exp.exponent/cache/DocumentPicker/57d6add2-1bc6-4cca-90d1-185864d83c79.xlsx which is not been read this file uri I got from the console.log(res.uri). needs the expert decisions in a few of my questions:

  • is the expo document picker okay to use or third-party react native document picker?
  • path is being picked but further not readable why?
  • I used the third-party React native document picker but got errors in appregistry and the main failed to load the module.
  • The main output I want is to read the Excel file from the documents folder and show the data in tables...

I am building an app that should show the Excel file data where I further want to do analysis but got stuck here.

0

There are 0 best solutions below