Thief of Wealth

https://handsondataviz.org/google-sheets-api-key.html

 

Get Your Google Sheets API Key | Hands-On Data Visualization

Tell your story and show it with data, using free and easy-to-learn tools on the web. This introductory book teaches you how to design interactive charts and customized maps for your website, beginning with easy drag-and-drop tools, such as Google Sheets,

handsondataviz.org

 

apiKey는 위 방법으로 얻고

 

라이브러리는 아래꺼 사용하기

 

import { GoogleSpreadsheet, GoogleSpreadsheetRow } from "google-spreadsheet";
import { useEffect, useState } from "react";

export const getGoogleSheet: () => Promise<GoogleSpreadsheet> = async () => {
  const doc = new GoogleSpreadsheet(
    "시트아이디",
    {
      apiKey: 키,
    }
  );

  await doc.loadInfo();
  return doc;
};

// 구글 시트 조회하는 custom useHook
const useGoogleSheet = (sheetId: string) => {
  const [googleSheetRows, setGoogleSheetRows] = useState<
    GoogleSpreadsheetRow[]
  >([]);

  const fetchGoogleSheetRows = async () => {
    const googleSheet = await getGoogleSheet();
    const sheetsByIdElement = googleSheet.sheetsByTitle[sheetId];
    const rows = await sheetsByIdElement.getRows();
    setGoogleSheetRows(rows);
  };

  console.log("rows", googleSheetRows);

  useEffect(() => {
    fetchGoogleSheetRows();
  }, []);

  return [googleSheetRows];
};

export default useGoogleSheet;

'개발' 카테고리의 다른 글

사이트 동영상 다운로드 받기  (0) 2023.05.07
vscode inlayHints 기능 활성화하기  (0) 2023.04.29
profile on loading

Loading...