export react-native table data in excel, csv and pdf format?

Viewed 271

I have created a table using react-native-table-component library Link: https://www.npmjs.com/package/react-native-table-component

I want to export my table data in different formats like excel(xlxs), csv and pdf. i have found lot of solution and read so many libraries but didn't got any solution. So, please suggest me the solution of this problem.

Code:

import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import { Table, Row, Rows } from 'react-native-table-component';
 
export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      tableHead: ["Name", "Country", "City", "Mobile", "Salary"],
      tableData: [
    ["John Anderson Wilson", "America", "Newyork", "123", "$22"],
    ["David", null, "Toronto", "056", null],
    [
      "David Malan",
      "United Kingdom of Great Britain and Northern Ireland",
      null,
      "242",
      "S23"
    ],
    ["Smith", "Japan", "", null, "$32"]
  ]
    }
  }
 
  render() {
    const state = this.state;
    return (
      <View style={styles.container}>
        <Table borderStyle={{borderWidth: 2, borderColor: '#c8e1ff'}}>
          <Row data={state.tableHead} style={styles.head} textStyle={styles.text}/>
          <Rows data={state.tableData} textStyle={styles.text}/>
        </Table>
      </View>
    )
  }
}
 
const styles = StyleSheet.create({
  container: { flex: 1, padding: 16, paddingTop: 30, backgroundColor: '#fff' },
  head: { height: 40, backgroundColor: '#f1f8ff' },
  text: { margin: 6 }
}); 

0 Answers
Related