Hi all,
Using xlsx, expo-document-picker and expo-file-system. Below is my function to select an Excel workbook from device.
Works well when selecting a file, but expo app closes when file selection is cancelled, with no error log
const pickDocument = async () => {
setIsLoading(true);
let result = await DocumentPicker.getDocumentAsync({
copyToCacheDirectory: true,
type: [
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
],
});
setFileName(result.name);
if (!result.canceled) {
let file = result.uri;
let b64 = await FileSystem.readAsStringAsync(file, {
encoding: FileSystem.EncodingType.Base64,
});
let workbook = XLSX.read(b64, { type: 'base64' });
let sheet_name_list = workbook.SheetNames;
let data = XLSX.utils.sheet_to_json(workbook.Sheets[sheet_name_list[0]]);
setCsvData(data);
}
setIsLoading(false);
};