1.0.185 • Published 9 months ago

ts-excel-app v1.0.185

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months 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

9 months ago

1.0.183

11 months ago

1.0.182

11 months ago

1.0.180

11 months ago

1.0.179

11 months ago

1.0.178

11 months ago

1.0.176

11 months ago

1.0.175

11 months ago

1.0.174

11 months ago

1.0.173

11 months ago

1.0.172

11 months ago

1.0.171

11 months ago

1.0.170

11 months ago

1.0.169

11 months ago

1.0.168

11 months ago

1.0.167

11 months ago

1.0.166

11 months ago

1.0.165

11 months ago

1.0.164

11 months ago

1.0.163

11 months ago

1.0.162

11 months ago

1.0.161

11 months ago

1.0.160

11 months ago

1.0.159

11 months ago

1.0.158

11 months ago

1.0.157

11 months ago

1.0.156

11 months ago

1.0.155

11 months ago

1.0.154

11 months ago

1.0.153

11 months ago

1.0.152

11 months ago

1.0.151

11 months ago

1.0.150

11 months ago

1.0.149

11 months ago

1.0.148

11 months ago

1.0.147

11 months ago

1.0.146

11 months ago

1.0.145

11 months ago

1.0.144

11 months ago

1.0.143

11 months ago

1.0.142

11 months ago

1.0.141

11 months ago

1.0.140

11 months ago

1.0.139

11 months ago

1.0.138

11 months ago

1.0.137

11 months ago

1.0.136

11 months ago

1.0.135

11 months ago

1.0.134

11 months ago

1.0.133

11 months ago

1.0.132

11 months ago

1.0.131

11 months ago

1.0.130

11 months ago

1.0.129

11 months ago

1.0.128

11 months ago

1.0.127

11 months ago

1.0.126

11 months ago

1.0.124

11 months ago

1.0.123

11 months ago

1.0.122

11 months ago

1.0.121

11 months ago

1.0.120

11 months ago

1.0.119

11 months ago

1.0.118

11 months ago

1.0.117

11 months ago

1.0.116

11 months ago

1.0.115

11 months ago

1.0.114

11 months ago

1.0.113

11 months ago

1.0.112

11 months ago

1.0.111

11 months ago

1.0.110

11 months ago

1.0.109

11 months ago

1.0.108

11 months ago

1.0.107

11 months ago

1.0.106

11 months ago

1.0.105

11 months ago

1.0.104

11 months ago

1.0.103

11 months ago

1.0.102

11 months ago

1.0.101

11 months ago

1.0.100

11 months ago

1.0.99

11 months ago

1.0.98

11 months ago

1.0.97

11 months ago

1.0.96

11 months ago

1.0.95

11 months ago

1.0.94

11 months ago

1.0.93

11 months ago

1.0.92

11 months ago

1.0.91

11 months ago

1.0.90

11 months ago

1.0.89

11 months ago

1.0.88

11 months ago

1.0.87

11 months ago

1.0.86

11 months ago

1.0.85

11 months ago

1.0.84

11 months ago

1.0.83

11 months ago

1.0.82

11 months ago

1.0.81

11 months ago

1.0.80

11 months ago

1.0.79

11 months ago

1.0.78

11 months ago

1.0.77

11 months ago

1.0.76

11 months ago

1.0.75

11 months ago

1.0.74

11 months ago

1.0.73

11 months ago

1.0.72

11 months ago

1.0.71

11 months ago

1.0.70

11 months ago

1.0.69

11 months ago

1.0.68

11 months ago

1.0.67

11 months ago

1.0.66

11 months ago

1.0.65

11 months ago

1.0.64

11 months ago

1.0.63

11 months ago

1.0.62

11 months ago

1.0.61

11 months ago

1.0.60

11 months ago

1.0.59

11 months ago

1.0.58

11 months ago

1.0.57

11 months ago

1.0.56

11 months ago

1.0.55

11 months ago

1.0.54

11 months ago

1.0.53

11 months ago

1.0.52

11 months ago

1.0.51

11 months ago

1.0.50

11 months ago

1.0.49

11 months ago

1.0.48

11 months ago

1.0.47

11 months ago

1.0.46

11 months ago

1.0.45

11 months ago

1.0.44

11 months ago

1.0.43

11 months ago

1.0.42

11 months ago

1.0.41

11 months ago

1.0.40

11 months ago

1.0.39

11 months ago

1.0.38

11 months ago

1.0.37

11 months ago

1.0.36

11 months ago

1.0.35

11 months ago

1.0.34

11 months ago

1.0.33

11 months ago

1.0.32

11 months ago

1.0.31

11 months ago

1.0.30

11 months ago

1.0.29

11 months ago

1.0.28

11 months ago

1.0.27

11 months ago

1.0.26

11 months ago

1.0.25

11 months ago

1.0.24

11 months ago

1.0.23

11 months ago

1.0.22

11 months ago

1.0.21

11 months ago

1.0.20

11 months ago

1.0.19

11 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.16

11 months ago

1.0.15

11 months ago

1.0.14

11 months ago

1.0.13

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago