1.0.185 • Published 2 years ago

ts-excel-app v1.0.185

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago
# ts-excel-app

ts-excel-app is a JavaScript library for creating and managing Excel workspaces in a web application. It provides a set of components and methods that allow users to interact with Excel-like spreadsheets in their browser.

## Installation

To install ts-excel-app, you can use npm or yarn:

```bash
npm install ts-excel-app

or

yarn add ts-excel-app

Usage

Import the necessary components and styles in your application:

import { WorkSpace, ExcelProvider, useExcel } from 'ts-excel-app';

Create a functional component for your application and use the useExcel hook to access the Excel methods:

function App() {
  const { externalMethods } = useExcel();
  const {
    addRow,
    addColumn,
    setPrivateColumns,
    getPrivateColumns,
    clearPrivateColumns,
    setEncryptedColumns,
    getEncryptedColumns,
    clearEncryptedColumns,
    refreshWorkSpace,
    exportToExcel,
    exportToJson,
    uploadExcelFile,
    uploadJsonData,
  } = externalMethods;

  const json = [
    // Your JSON data goes here
  ];

  return (
    <>
      <button onClick={() => addRow()}>Add Row</button>
      <button onClick={() => addColumn()}>Add Column</button>
      <button onClick={() => setPrivateColumns(['Header1', 'Header2'])}>Set Private Columns</button>
      <button onClick={() => console.log(getPrivateColumns())}>Get Private Columns</button>
      <button onClick={() => clearPrivateColumns()}>Clear Private Columns</button>
      <button onClick={() => setEncryptedColumns(['Header1', 'Header2'])}>Set Encrypted Columns</button>
      <button onClick={() => console.log(getEncryptedColumns())}>Get Encrypted Columns</button>
      <button onClick={() => clearEncryptedColumns()}>Clear Encrypted Columns</button>
      <button onClick={() => refreshWorkSpace()}>Refresh Workspace</button>
      <button onClick={() => exportToExcel()}>Download as XLSX</button>
      <button onClick={() => exportToJson()}>Download as JSON</button>
      <div>
        <input type="file" id="demo" accept=".xls,.xlsx" onChange={uploadExcelFile}></input>
      </div>
      <button onClick={() => uploadJsonData(json)}>Upload Json</button>
    </>
  );
}

ReactDOM.render(
  <React.StrictMode>
    <ExcelProvider
      onAddRow={() => console.log('Row Added')}
      onAddColumn={() => console.log('Column Added')}
    >
      <WorkSpace
        showAddRow={false}
        showAddColumn={false}
        onCellChange={() => console.log('Cell Value Changed')}
        onHeaderChange={() => console.log('Header Value Changed')}
        onRowDelete={() => console.log('Row Deleted')}
        onRowCopy={() => console.log('Row Copied')}
        onRowCut={() => console.log('Row cut')}
        onRowPaste={() => console.log('Row paste')}
        onInsertRow={() => console.log('Row inserted')}
        onClearRow={() => console.log('Row Cleared')}
        onColumnDelete={() => console.log('Column Deleted')}
        onColumnCopy={() => console.log('Column Copied')}
        onColumnCut={() => console.log

('Column cut')}
        onColumnPaste={() => console.log('Column paste')}
        onInsertColumn={() => console.log('Column inserted')}
        onClearColumn={() => console.log('Column Cleared')}
      />
      <App />
    </ExcelProvider>
  </React.StrictMode>,
  document.getElementById('root')
);

Components

WorkSpace

The WorkSpace component provides an Excel-like interface for users to interact with the spreadsheet. It renders the grid, headers, and other components required for Excel functionality.

Props

  • showAddRow (boolean, optional): Determines whether to show the "Add Row" button. Default is false.
  • showAddColumn (boolean, optional): Determines whether to show the "Add Column" button. Default is false.
  • headerStyle (Object): Pass a object of style properties to override the default style of headers
  • cellStyle (Object): Pass a object of style properties to override the default style of cells

Event Handlers

The WorkSpace component provides several event handlers that you can pass as props:

  • onCellChange: Triggered when a cell value is changed.
  • onHeaderChange: Triggered when a header value is changed.
  • onRowDelete: Triggered when a row is deleted.
  • onRowCopy: Triggered when a row is copied.
  • onRowCut: Triggered when a row is cut.
  • onRowPaste: Triggered when a row is pasted.
  • onInsertRow: Triggered when a row is inserted.
  • onClearRow: Triggered when a row is cleared.
  • onColumnDelete: Triggered when a column is deleted.
  • onColumnCopy: Triggered when a column is copied.
  • onColumnCut: Triggered when a column is cut.
  • onColumnPaste: Triggered when a column is pasted.
  • onInsertColumn: Triggered when a column is inserted.
  • onClearColumn: Triggered when a column is cleared.

ExcelProvider

The ExcelProvider component wraps your application and provides the necessary context for the Excel methods to work. It accepts two event handlers as props:

  • onAddRow: Triggered when a row is added.
  • onAddColumn: Triggered when a column is added.

Methods

The useExcel hook provides access to the following methods:

  • addRow(): Adds a new row to the Excel workspace.
  • addColumn(): Adds a new column to the Excel workspace.
  • setPrivateColumns(columns: string[]): Sets the specified columns as private columns.
  • getPrivateColumns(): string[]: Returns an array of the current private columns.
  • clearPrivateColumns(): Clears all the private columns.
  • setEncryptedColumns(columns: string[]): Sets the specified columns as encrypted columns.
  • getEncryptedColumns(): string[]: Returns an array of the current encrypted columns.
  • clearEncryptedColumns(): Clears all the encrypted columns.
  • refreshWorkSpace(): Refreshes the Excel workspace.
  • exportToExcel(): Downloads the Excel workspace as an XLSX file.
  • exportToJson(): Downloads the Excel workspace as JSON data.
  • uploadExcelFile(event: React.ChangeEvent<HTMLInputElement>): Uploads an Excel (XLSX) file to the workspace.
  • uploadJsonData(data: any): Uploads JSON data to the workspace.

Feel free to adjust the descriptions and examples as needed for your README file.

That's it! You're ready to start using ts-excel-app in your web application. If you have any further questions or need additional assistance, please let us know.

1.0.185

2 years ago

1.0.183

3 years ago

1.0.182

3 years ago

1.0.180

3 years ago

1.0.179

3 years ago

1.0.178

3 years ago

1.0.176

3 years ago

1.0.175

3 years ago

1.0.174

3 years ago

1.0.173

3 years ago

1.0.172

3 years ago

1.0.171

3 years ago

1.0.170

3 years ago

1.0.169

3 years ago

1.0.168

3 years ago

1.0.167

3 years ago

1.0.166

3 years ago

1.0.165

3 years ago

1.0.164

3 years ago

1.0.163

3 years ago

1.0.162

3 years ago

1.0.161

3 years ago

1.0.160

3 years ago

1.0.159

3 years ago

1.0.158

3 years ago

1.0.157

3 years ago

1.0.156

3 years ago

1.0.155

3 years ago

1.0.154

3 years ago

1.0.153

3 years ago

1.0.152

3 years ago

1.0.151

3 years ago

1.0.150

3 years ago

1.0.149

3 years ago

1.0.148

3 years ago

1.0.147

3 years ago

1.0.146

3 years ago

1.0.145

3 years ago

1.0.144

3 years ago

1.0.143

3 years ago

1.0.142

3 years ago

1.0.141

3 years ago

1.0.140

3 years ago

1.0.139

3 years ago

1.0.138

3 years ago

1.0.137

3 years ago

1.0.136

3 years ago

1.0.135

3 years ago

1.0.134

3 years ago

1.0.133

3 years ago

1.0.132

3 years ago

1.0.131

3 years ago

1.0.130

3 years ago

1.0.129

3 years ago

1.0.128

3 years ago

1.0.127

3 years ago

1.0.126

3 years ago

1.0.124

3 years ago

1.0.123

3 years ago

1.0.122

3 years ago

1.0.121

3 years ago

1.0.120

3 years ago

1.0.119

3 years ago

1.0.118

3 years ago

1.0.117

3 years ago

1.0.116

3 years ago

1.0.115

3 years ago

1.0.114

3 years ago

1.0.113

3 years ago

1.0.112

3 years ago

1.0.111

3 years ago

1.0.110

3 years ago

1.0.109

3 years ago

1.0.108

3 years ago

1.0.107

3 years ago

1.0.106

3 years ago

1.0.105

3 years ago

1.0.104

3 years ago

1.0.103

3 years ago

1.0.102

3 years ago

1.0.101

3 years ago

1.0.100

3 years ago

1.0.99

3 years ago

1.0.98

3 years ago

1.0.97

3 years ago

1.0.96

3 years ago

1.0.95

3 years ago

1.0.94

3 years ago

1.0.93

3 years ago

1.0.92

3 years ago

1.0.91

3 years ago

1.0.90

3 years ago

1.0.89

3 years ago

1.0.88

3 years ago

1.0.87

3 years ago

1.0.86

3 years ago

1.0.85

3 years ago

1.0.84

3 years ago

1.0.83

3 years ago

1.0.82

3 years ago

1.0.81

3 years ago

1.0.80

3 years ago

1.0.79

3 years ago

1.0.78

3 years ago

1.0.77

3 years ago

1.0.76

3 years ago

1.0.75

3 years ago

1.0.74

3 years ago

1.0.73

3 years ago

1.0.72

3 years ago

1.0.71

3 years ago

1.0.70

3 years ago

1.0.69

3 years ago

1.0.68

3 years ago

1.0.67

3 years ago

1.0.66

3 years ago

1.0.65

3 years ago

1.0.64

3 years ago

1.0.63

3 years ago

1.0.62

3 years ago

1.0.61

3 years ago

1.0.60

3 years ago

1.0.59

3 years ago

1.0.58

3 years ago

1.0.57

3 years ago

1.0.56

3 years ago

1.0.55

3 years ago

1.0.54

3 years ago

1.0.53

3 years ago

1.0.52

3 years ago

1.0.51

3 years ago

1.0.50

3 years ago

1.0.49

3 years ago

1.0.48

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.44

3 years ago

1.0.43

3 years ago

1.0.42

3 years ago

1.0.41

3 years ago

1.0.40

3 years ago

1.0.39

3 years ago

1.0.38

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.30

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago