0.1.4 • Published 3 years ago

simpol-google-sheet v0.1.4

Weekly downloads
82
License
-
Repository
-
Last release
3 years ago

About

simpol-google-sheet is an angular library for retrieving, updating data from google spread sheet.

Getting started

npm install simpol-google-sheet

Usage

Import GSheetModule

app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { GSheetModule } from 'simpol-google-sheet';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    GSheetModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Edit package.json and add this

package.json
  "browser": {
    "path": false,
    "os": false,
    "child_process": false,
    "fs": false
  },

Edit tsconfig and add this inside the compilerOptions

tsconfig.json
"compilerOptions": {
    ...
    "paths": {
        "crypto": [
            "node_modules/crypto-browserify"
            ],
        "stream": [
            "node_modules/stream-browserify"
            ]
        }
    ...

Put this to your index.html tag. It will get rid of errors related to accessing the global as it substitutes it with the window.

index.html
<head>
  <script>
    if (global === undefined) {
        var global = window;
    }
</script>
...
</head>

Add the following imports in your polyfills

src/polyfills.ts
import * as process from 'process';
(window as any).process = process;
import { Buffer } from 'buffer';
(window as any).Buffer = Buffer;

Add google-sheet component in the html

app.component.html
<google-sheet></google-sheet>

Add GoogleSheetService in the app component and provide credentials

app.component.ts
import { Component, OnInit } from '@angular/core';
import { GoogleSheetService } from 'simpol-google-sheet';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {

  constructor(private googleSheet: GoogleSheetService){
  }

  ngOnInit(): void{
        this.googleSheet.init({
          credentials: {
            client_email: '<--- GOOGLE EMAIL --->',
            private_key: '<--- GOOGLE PRIVATE KEY --->'
          },
          sheetId: '<--- GOOGLE SHEET ID --->'
        });
  }
}

Inputs of google-sheet component

InputTypeDefaultDescription
editablebooleanfalseWhen set to true, allows cell editing and updates google spread sheet data almost in realtime

Outputs of google-sheet component

OutputDescription
(itemClick)Emits row index and row data when row is clicked

Methods of GoogleSheetService

NameParameter & TypesDescription
getSheetByIndex(index)index: numberGet sheet by index
getSheetByTitle(title)title: stringGet sheet by title
loadRows(sheetIndex)sheetIndex: number, row: anyLoad rows by sheet index
addRow(sheet, row)sheet: number or string, row: anyAdd single row to the sheet
addRows(sheet, ...rows )sheet: number or string, ...rows Adds multiple rows
deleteRow(sheet, rowIndex )sheet: number or string, rowIndex: numberDelete row
updateRowByField(sheet, rowIndex, fieldName, value)sheet: number or string, rowIndex: number, fieldName: string, value: anyUpdate cell by using fieldname
addSheet(title)title: stringAdd new sheet to the document
setTitle(title)title: stringSet title to the document
getData$()noneget data as observable returns headers and rows of the sheet
0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.6

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago