Export Data to Excel with React Native

Learn How to Export JSON data from your React Native Application to Excel using react-native-fs and xlsx

Rushikesh Vidhate
2 min readJan 18, 2021

Requirements

The final code for this example can be found here.

Steps

  1. Create a new react-native project
  2. Install dependencies ( react-native-fs & xlsx )
  3. Setup storage permission
  4. Implement Export Functionality
  5. Final Run & Output

Step 1: Create a new react-native project

Run the following commands :

>> npx react-native init SampleReactNative>> cd SampleReactNative

After running these commands new project being created. Detailed article on step-by-step-guide-to-kick-off-your-first-react-native-project

Step 2: Install dependencies ( react-native-fs & xlsx )

#1: Install and link react-native-fs

>> npm install react-native-fs --save>> react-native link react-native-fs

#2: Install xlsx

>> npm i xlsx --save

Step 3: Setup storage permission ( WRITE_EXTERNAL_STORAGE )

Add the following line in android/app/src/main/AndroidMainfest.xml

<uses-permission android:name="android.permission.INTERNET" />...<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />...

Step 4: Implement Export Functionality

#1.Import react-native-fs and xlsx

var RNFS = require(‘react-native-fs’);import XLSX from ‘xlsx’

#2. Create exportDataToExcel function

#3. Final App.js

Step 5: Final Run & Output

>> react-native run-android

The final code for this example can be found here.

Thanks :)

--

--

Responses (2)