Added function to auto-adjust column width
This commit is contained in:
parent
e33e3a20c8
commit
b897fd5e5c
1 changed files with 40 additions and 1 deletions
41
app.js
41
app.js
|
@ -102,6 +102,37 @@ async function resetTableData() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function autoResizeColumns(spreadsheetId, sheetId, startColumnIndex, endColumnIndex) {
|
||||||
|
try {
|
||||||
|
const sheets = await createSheetsClient();
|
||||||
|
|
||||||
|
const request = {
|
||||||
|
spreadsheetId: spreadsheetId,
|
||||||
|
resource: {
|
||||||
|
requests: [
|
||||||
|
{
|
||||||
|
autoResizeDimensions: {
|
||||||
|
dimensions: {
|
||||||
|
sheetId: sheetId,
|
||||||
|
dimension: 'COLUMNS',
|
||||||
|
startIndex: startColumnIndex,
|
||||||
|
endIndex: endColumnIndex + 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await sheets.spreadsheets.batchUpdate(request);
|
||||||
|
console.log('Columns auto-resized successfully');
|
||||||
|
return response.data;
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error auto-resizing columns:', err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const splidCodes = await getSheetData(SPREADSHEET_ID, SHEET_RANGES.SPLID_CODES);
|
const splidCodes = await getSheetData(SPREADSHEET_ID, SHEET_RANGES.SPLID_CODES);
|
||||||
const userTags = await getSheetData(SPREADSHEET_ID, SHEET_RANGES.USER_TAGS);
|
const userTags = await getSheetData(SPREADSHEET_ID, SHEET_RANGES.USER_TAGS);
|
||||||
|
@ -131,6 +162,14 @@ async function main() {
|
||||||
// Update the sheet with the row data
|
// Update the sheet with the row data
|
||||||
await updateSheetData(SPREADSHEET_ID, SHEET_RANGES.DATA_ROW(i), [rowData]);
|
await updateSheetData(SPREADSHEET_ID, SHEET_RANGES.DATA_ROW(i), [rowData]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Sheets updated, adjusting column width.")
|
||||||
|
|
||||||
|
try {
|
||||||
|
await autoResizeColumns(SPREADSHEET_ID, SHEET_ID, COLUMN_INDICES.E, COLUMN_INDICES.M);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Failed to auto-resize columns, but data was updated successfully:', err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main().catch(console.error);
|
main().catch(console.error);
|
||||||
|
|
Loading…
Reference in a new issue