# Typescriptle google-spreadsheet ile google sheet duzenlemek

![](https://i.imgur.com/lZSfQcw.png)

* <https://github.com/theoephraim/node-google-spreadsheet> kutuphanesi ile guncelleme islemlerini yapabiliriz
* Dokumantasyonu icin [buraya](https://theoephraim.github.io/node-google-spreadsheet/#/?id=working-with-rows) bakabilirsiniz, [auth islemleri](https://theoephraim.github.io/node-google-spreadsheet/#/guides/authentication)

<details>

<summary>`worksheet` kullanmadan once `load` etmeniz gerekir, aksi halde hata verir</summary>

```typescript
await worksheet.loadHeaderRow()
const headers = worksheet.headerValues.entries()

await worksheet.loadCells({
	startRowIndex: rowIndex,
	endRowIndex: rowIndex + 1,
	startColumnIndex: colIndex,
	endColumnIndex: colIndex + 2,
})
const assetCell = worksheet.getCell(rowIndex, colIndex + assetOffset)
```

</details>

<details>

<summary>Ilk `row` ve `col` degerini header row olarak aldigi icin, $row_{sheet} = row_{code} + 1$</summary>

\- Yani \`sheet\` de yer alan \`2\` satir icin code icerisinden \`1\` indeksi ile erisirsiniz - Ayni durum \`col\` indeks hesabi icin de gecerlidir

</details>

<details>

<summary>`value = x` atamalarindan sonra `save` yapmayi unutmayin</summary>

```typescript
const assetCell = worksheet.getCell(rowIndex, colIndex + assetOffset)
assetCell.value = 4
await assetCell.save() // Bunu yapmazsaniz sheet'e yazmaz
```

</details>

## Periyodik Olarak Worksheet’e veri Gondermek

```typescript
import { JWT } from "google-auth-library"
import {
	GoogleSpreadsheet,
	type GoogleSpreadsheetWorksheet,
} from "google-spreadsheet"

export type GoogleSheetCredential = {
	client_email: string
	private_key: string
	spreadsheetId: string
	worksheetName: string
}
export type GoogleSheetConfig = { sheetIntervalHour?: number }
export type GoogleSheetManagerInit = GoogleSheetCredential & GoogleSheetConfig
export class GoogleSheetManager {
	private readonly spreadSheet: GoogleSpreadsheet

	private readonly worksheetName: string
	private readonly sheetIntervalHour: number

	intervalId?: NodeJS.Timeout

	constructor(init: GoogleSheetManagerInit) {
		const { spreadsheetId, client_email, private_key } = init
		const auth = new JWT({
			email: client_email,
			key: private_key,
			scopes: [
				"https://www.googleapis.com/auth/spreadsheets",
				"https://www.googleapis.com/auth/drive.file",
			],
		})
		this.spreadSheet = new GoogleSpreadsheet(spreadsheetId, auth)

		this.worksheetName = init.worksheetName
		this.sheetIntervalHour = init.sheetIntervalHour ?? 1
	}

	static async start(
		init: GoogleSheetManagerInit & {
			onPushInterval: (worksheet: GoogleSpreadsheetWorksheet) => Promise<void>
		}
	): Promise<GoogleSheetManager> {
		const sheetManager = new GoogleSheetManager(init)
		await sheetManager.spreadSheet.loadInfo()

		const worksheet =
			sheetManager.spreadSheet.sheetsByTitle[sheetManager.worksheetName]
		await worksheet.loadHeaderRow()

		await init.onPushInterval(worksheet)
		sheetManager.intervalId = setInterval(async () => {
			await init.onPushInterval(worksheet)
		}, sheetManager.sheetIntervalHour * 60 * 60 * 1000)
		return sheetManager
	}
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yemreak.com/arsiv/programming/typescriptle-google-spreadsheet-ile-google-sheet-duzenlemek.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
