allow multiple rows for template

This commit is contained in:
Ben Miller
2024-11-26 19:37:13 -07:00
parent 6c7092bc5e
commit cace87989c
2 changed files with 28 additions and 9 deletions

View File

@ -1,6 +1,23 @@
import { productTemplate } from "./productTemplate"
import { toastAndLog } from "./sheetUtils"
export function fillProductFromTemplate() {
let row = SpreadsheetApp.getCurrentCell().getRow()
var sheet = SpreadsheetApp.getActive().getActiveSheet()
if (sheet.getName() !== "product_inventory") {
console.log("skipping edit on sheet " + sheet.getName())
return
}
let selectedRanges = SpreadsheetApp.getActiveRangeList().getRanges()
if (selectedRanges == null || selectedRanges.length == 0) {
toastAndLog("Select ranges to be updated")
return
}
for (let i = 0; i < selectedRanges.length; i++) {
let range = selectedRanges[i]
let firstRow = range.getRow()
let lastRow = range.getLastRow()
for (let row = firstRow; row <= lastRow; row++) {
productTemplate(row)
}
}
}

View File

@ -7,13 +7,14 @@ import {
} from "./sheetUtils"
export function productTemplate(row: number) {
//TODO: just use the columns that exist, if they match
let updateColumns = [
"function",
"type",
"category",
"product_type",
"tags",
"price",
"base_price",
"shipping",
"weight (grams)",
]
@ -21,6 +22,7 @@ export function productTemplate(row: number) {
let productInventorySheet =
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("product_inventory")
let titleValue = getCellValueByColumnName(productInventorySheet, "title", row)
//TODO: Make this *much* faster
for (let i = 0; i < updateColumns.length; i++) {
let updateColumn = updateColumns[i]
let currentValue = getCellValueByColumnName(
@ -43,14 +45,14 @@ export function productTemplate(row: number) {
)
if (templateValue != "") {
console.log(
"template value for '" +
updateColumn +
"' is '" +
templateValue +
"'"
"template value for '" + updateColumn + "' is '" + templateValue + "'"
)
toastAndLog("updating '" + updateColumn + "' to '" + templateValue + "'")
let cell = getCellRangeByColumnName(productInventorySheet, updateColumn, row)
let cell = getCellRangeByColumnName(
productInventorySheet,
updateColumn,
row
)
cell.setValue(templateValue)
}
}